对于每个循环,
看来您的问题已基本得到解答。为了清楚起见,我将仅添加一些信息,并为这个问题提供答案。微软论坛上的一位用户 Ossiemac 指出 LateBinding 是一种可行的方法。正如 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 的对比——
~乔尔