我在网络共享上有一个.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.在这种情况下,它会给出找不到库的错误。这是一个错误吗?有解决方法吗?我忽略了什么?
答案 0 :(得分:3)
foreach循环,
看来您的问题已基本得到解答。为了清楚起见,我只会添加一些信息,并为这个问题提供答案。微软论坛上的用户Ossiemac注意到LateBinding was the way to go,正如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有一篇文章讨论contrast of EarlyBinding and LateBinding -
〜JOL