ForEachLoop,
看來您的問題已基本得到解答。爲了清楚起見,我只會添加一些信息,並提供這個問題的答案。正如Siddarth Rout所述,Microsoft論壇Ossiemac上的用戶指出LateBinding was the way to go。正如Siddarth所暗示的那樣,這意味着您不必擔心引用。 -
〜約爾
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
吉米·佩納有一篇文章討論contrast of EarlyBinding and LateBinding:
Ossiemac對電子郵件的發送,我已經重新格式化並放在這裏使用LateBinding提供了一些示例代碼
我相信你正在使用'EarlyBinding'你有沒有考慮過使用'LateBinding(LB)'? LB的好處是你不必擔心在不同的計算機上運行不同的版本。代碼將始終與正在運行代碼的pc中存在的版本綁定。請參閱他的鏈接:http://support.microsoft.com/kb/245115 –
謝謝。我保留這個選項。相反,我問爲什麼其他兩個引用自動更新在任何方向,但該Outlook具體而言,不。如果是這樣,我將不得不使用後期綁定,你 – ForEachLoop
我遇到了同樣的問題,使用Excel VBA。我還注意到,對Microsoft Office和Microsoft Excel庫的(早期綁定)引用會自動在版本12和14之間切換,但對Microsoft Outlook的引用不會。也就是說,它的自動更改從12到14,但從未回到12. – comecme