运行下面的InvokeMember
方法时出错。错误是UNKNOWN NAME
。我检查了拼写,这是正确的。在Outlook
我在信任中心Enable Macros
。为了让这个工作有什么我可能会失踪的吗?感谢
VB代码:
olApp.GetType().InvokeMember("Run", Reflection.BindingFlags.Default Or
Reflection.BindingFlags.InvokeMember,
Nothing, olApp, New Object() {"nameOfMacro"})
答案 0 :(得分:0)
好吧,似乎InvokeMember
无效。答案是像在宏中一样制作代码并运行它。例如:
Private Sub MoveAttachmentToFolder()
Dim olNs = olApp.GetNamespace("MAPI")
Dim subFolderA = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Parent.Folders("subFolderA")
Dim subFolderB = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Parent.Folders("subFolderB")
For Each mi As Outlook.MailItem In subFolderA.Items
If mi.Attachments.Count = 1 Then
'remember interops use 1 based arrays not zero
Dim fileName As String = "some path" & mi.Attachments(1).FileName
mi.Attachments(1).SaveAsFile(fileName)
mi.Move(subFolderB)
End If
Next
End Sub