outlook2007怎么执行宏代码?
我的代码如下:SubNewMailSaveAttachemnets(myMailAsOutlook.MailItem)'//outlook收到新邮件是将邮件的附件自动放到...
我的代码如下:Sub NewMailSaveAttachemnets(myMail As Outlook.MailItem)'// outlook 收到新邮件是 将邮件的附件 自动放到指定位置 On Error Resume Next Dim mail As Outlook.MailItem Dim Fso As Object Dim myOlExp As Outlook.Explorer '//outlook Dim myOlSel As Outlook.Selection '//outlook所在选择项 Set Fso = CreateObject("Scripting.FileSystemObject") '//FSO文件对象 Dim MsgTxt As String Dim x As Integer Dim Folder As String Dim reg As String Dim MyFileName As String Dim myT1, myT2, myT3, myT As String Set myOlExp = Application.ActiveExplorer '//指向对象 outlook '// Set myOlSel = myOlExp.Selection Dim vItem As Outlook.Attachment reg = "\d+" '//正则表达式 If myMail.Attachments.Count > 0 Then For i = 1 To myMail.Attachments.Count myT1 = CStr(Format(myMail.SentOn, "yyyymmdd")) myT2 = myMail.SenderName Set vItem = myMail.Attachments(i) MyFileName = vItem.FileName myT = path0 & "\" & myT1 & "-" & myT2 & "-" & MyFileName '//Debug.Print MyFileName If InStr(MyFileName, "思考A3") = 0 Or InStr(MyFileName, "广发纳斯特乐睿1号") = 0 Then '//判断是否包含该月份的文件夹,有则保存在文件夹 ,无则创建文件 Folder = "E:\outlook\" & Val(Mid(getRegtoString(reg, MyFileName), 5, 2)) & "月份" '//判断月份 If Not Fso.FolderExists("Folder") Then '//无则创建文件夹 Fso.CreateFolder (Folder) End If vItem.SaveAsFile Folder & "\" & vItem.FileName '//保存附件路径 Else vItem.SaveAsFile "E:+\outlook\down\" & vItem.FileName '//保存到根目录文件夹 End If Next i End IfEnd Sub不知道有没有问题,我打开Outlook2007客户端之后按Alt+F11,在如图所示的地方写了代码,如何在打开outlook客户端的时候能够自动执行这段代码呢?主界面是第二张图,还有我点击编译的时候会报错,报错如第三张图所示,这个有没有影响呢?
展开
2个回答
展开全部
Private Sub Workbook_Open()改成
Private Sub Workbook_BeforeSave()
在保存之前执行代码。
Private Sub Workbook_BeforeSave()
在保存之前执行代码。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询