Word for Mac 宏无法创建outook电子邮件

问题描述 投票:0回答:1

我在 Mac 或 Mac OS 上的经验为零。 我有一个我们办公室的人使用的宏,他们运行 Word for windows,将当前 word(for windows)文档复制到剪贴板,打开 outlook,创建新消息,粘贴 word 的当前内容,填写电子邮件地址和主题。但是当我运行将宏添加到使用 mac 的用户并尝试运行它时,我收到错误消息 运行时 429 - “Active X 无法创建对象”

Sub OpenEmailWithAttachment()
    ' Declare variables
    Dim OutApp As Object
    Dim OutMail As Object
    Dim FileName As String
    Dim EmailAddress As String
    Dim EmailSubject As String
    Dim AttachmentPath As String
    Dim WordApp As Object
    Dim WordDoc As Object
    
    ' Set the email address and attachment file path
    EmailAddress = ActiveDocument.MailMerge.DataSource.DataFields("Email").Value
    ' AttachmentPath = "path/attachment.pdf"
 
    ' Set the email subject
    EmailSubject = "Request" & ActiveDocument.MailMerge.DataSource.DataFields("RqId").Value
  
    ' Create a new Outlook email message
    Set OutApp = CreateObject("Outlook.Application")

** the macro stops on the previous line with error Runtime 429 - "Active X can't create object' 

    Set OutMail = OutApp.CreateItem(0)
    
    ' Set the email recipient, subject, and body
    With OutMail
        .To = EmailAddress
        .Subject = EmailSubject
        
        ' Copy the contents of the current document to the email body
        Set WordApp = GetObject(, "Word.Application")
        Set WordDoc = WordApp.ActiveDocument
        WordDoc.Content.Copy
        .Display
        .GetInspector.WordEditor.Range.Paste
        
        ' Attach the separate PDF file to the email
        ' .Attachments.Add AttachmentPath
        
        ' Display the email and send it
        .Display
       
    End With
    
    ' Clean up the Outlook objects
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

我用谷歌搜索了错误 429,老实说,我不明白 Active X 是什么以及为什么宏不会运行。 在 windows 上完美运行的 Visual basic 代码不能在 mac 上运行,这真是太疯狂了,但这就是我来这里的原因,希望了解 mac 思想的人能给我指明正确的方向。

vba macos outlook word macos-catalina
1个回答
0
投票

Mac 应用程序是单实例,因此如果 Outlook 已经在运行,则无法创建新对象。

Dim outlookApp As Object
On Error Resume Next
Set outlookApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If outlookApp Is Nothing Then _
Set outlookApp = CreateObject("Outlook.Application ")
© www.soinside.com 2019 - 2024. All rights reserved.