I have zero experience on Mac or Mac OS. I have a macro used by folks in our office who run Word for windows that copies the current word (for windows) document to the clipboard, opens outlook, creates a new message, pastes in the current contents of word, fills in the email address and subject. But when I run add the macro to the user with a mac and try to run it, I get the error message Runtime 429 - "Active X can't create object'
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
I have googled the error 429 and to be honest I don't understand what Active X is and why the macro won't run. It is crazy that Visual basic code that runs on windows perfectly won't run on a mac but that is why I here, hoping someone who understands the mind of mac can point me in the right direction.
Mac applications are single instance, so if Outlook is already running, you can't create a new object.
That is what you actually do in case of Word. See You receive run-time error 429 when you automate Office applications for more information about the error message.
The MAC OS uses AppleScript for automating Office applications because there is no ActiveX technology available for the Mac OS. But the error codes are remains the same as well as reasons why you get such errors.
Also starting from Office 2016 for Mac VBA supports commands such as
GrantAccessToMultipleFilesandAppleScriptTaskthat are not supported in other versions of Office. If your solution targets multiple versions of Office, Microsoft recommend that you use conditional compilation. UseMAC_OFFICE_VERSIONto determine which version of VBA the user is running. The#If Macconditional is the same in Office for Mac 2011.