Outlook对象库不能在版本12和14之间切换
我在网络共享上有一个.dotm模板文件。 有对Word,Office和Outlook对象库的引用的宏。 我们使用两种不同的平台,Windows XP和Windows 7以及Microsoft Office 2007和Office 2010.当用户打开模板文件时,Word和Office的引用将自动调整并相应地进行调整(即,它们设置为Microsoft Word 12对象库或Microsoft Word 14对象库),并且宏运行没有问题。
Microsoft Outlook对象库从版本12正确切换到14.它无法从版本14正确切换到12.在这种情况下,它会提供找不到该库的错误。 这是一个错误? 有没有解决方法? 我忽略的东西?
foreach循环,
看来你的问题已经在很大程度上得到了回答。 为了清楚起见,我只会添加一些信息,并提供这个问题的答案。 微软论坛Ossiemac的一位用户指出,LateBinding就是要走的路,正如Siddarth Rout所说的那样。 正如Siddarth所暗示的那样,这意味着您不必担心引用。
Ossiemac提供了一些使用LateBinding发送电子邮件的示例代码,我已将其重新格式化并放置在此处:
Private Sub btnLateBindMethod_Click()
' Variables used for LateBinding
Dim objOutlook As Object 'Outlook.Application
Dim objEmail As Object 'Outlook.MailItem
Dim objNameSpace As Object 'Outlook.NameSpace
Const OutLookMailItem As Long = 0 'For Late Binding
Const OutLookFolderInbox As Long = 6 'For Late Binding
Const OutLookFormatHTML As Long = 2 'For Late Binding
Dim strSubject As String
Dim strAddress As String
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
On Error GoTo 0
If objOutlook Is Nothing Then
Set objOutlook = CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
objNameSpace.GetDefaultFolder(OutLookFolderInbox).Display
End If
Set objEmail = objOutlook.CreateItem(OutLookMailItem)
strSubject = "Hello World"
With objEmail
'.To = strToAddress 'Commented to prevent accidental send
.Subject = strSubject
.BodyFormat = OutLookFormatHTML
.Display
'Full Name of window can change depending on Tools -> Options -> Mail Format
'Changing this option for outgoing mail changes the window name.
'However, AppActivate appears not to require entire name but needs up to end
'of - Message which is included in heading following the Subject string
'irrespective of the Mail Format option chosen.
AppActivate (strSubject & " - Message")
End With
End Sub
Jimmy Pena有一篇文章讨论EarlyBinding和LateBinding的对比 -
〜JOL
链接地址: http://www.djcxy.com/p/10937.html上一篇: Outlook Object Library Does Not Switch Between Versions 12 And 14