Davisro
asked on
Excel VBA for MAC OS - Email Workbook
If I want to attach an Excel workbook to an email in Outlook that is MAC compatible, do I need to write a routine in Apple Script as described by Ron DeBruin in 2012?
https://msdn.microsoft.com/en-us/library/hh859489(v=office.14).aspx
When I use the code below, my MAC users get a run-time error 429: "ActiveX component can't create object". But there are no ActiveX form objects in the file
Sub AttachEmail()
Dim sFileName As String, sEmployeeName As String, sFileDate As String, sSender As String
Dim sFileDateExt As String, sCurrFileName As String, sFilePath As String, sFullPath As String
Dim sLocation As String, sTK_Loc As String
Dim OutApp As Object, OutMail As Object
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If OutApp Is Nothing Then
Set OutApp = CreateObject("Outlook.Appl ication")
End If
Set OutMail = OutApp.CreateItem(0)
With Sheet1
sEmployeeName = .Range("B2").Value
sLocation = .Range("C2").Value
sTK_Loc = .Range("D2").Value
End With
sFileDate = Sheet4.Range("E14").Value
sFileDateExt = Year(sFileDate) & "." & Format(Month(sFileDate), "00") & ".xlsm"
sFileName = sEmployeeName & " - " & sTK_Loc & " Timesheet - " & sFileDateExt
sFilePath = ActiveWorkbook.Path
sFullPath = sFilePath & "/" & sFileName
Application.ScreenUpdating = False
With Sheet4
If .ProtectContents = True Then
.Unprotect
End If
.Range("O3:P3") = Array("Submitted:", Now())
.Range("O4:P4") = Array("Sender:", OutApp.session.accounts.It em(1).Disp layName)
.Protect
End With
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs (sFullPath)
Application.DisplayAlerts = True
Application.ScreenUpdating = True
On Error Resume Next
With OutMail
.to = "HRTimesheets@yourcompany. com"
.Subject = sFileName
.Attachments.Add ActiveWorkbook.FullName
.Display
'.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
ActiveWorkbook.Close SaveChanges:=True
End Sub
https://msdn.microsoft.com/en-us/library/hh859489(v=office.14).aspx
When I use the code below, my MAC users get a run-time error 429: "ActiveX component can't create object". But there are no ActiveX form objects in the file
Sub AttachEmail()
Dim sFileName As String, sEmployeeName As String, sFileDate As String, sSender As String
Dim sFileDateExt As String, sCurrFileName As String, sFilePath As String, sFullPath As String
Dim sLocation As String, sTK_Loc As String
Dim OutApp As Object, OutMail As Object
On Error Resume Next
Set OutApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If OutApp Is Nothing Then
Set OutApp = CreateObject("Outlook.Appl
End If
Set OutMail = OutApp.CreateItem(0)
With Sheet1
sEmployeeName = .Range("B2").Value
sLocation = .Range("C2").Value
sTK_Loc = .Range("D2").Value
End With
sFileDate = Sheet4.Range("E14").Value
sFileDateExt = Year(sFileDate) & "." & Format(Month(sFileDate), "00") & ".xlsm"
sFileName = sEmployeeName & " - " & sTK_Loc & " Timesheet - " & sFileDateExt
sFilePath = ActiveWorkbook.Path
sFullPath = sFilePath & "/" & sFileName
Application.ScreenUpdating
With Sheet4
If .ProtectContents = True Then
.Unprotect
End If
.Range("O3:P3") = Array("Submitted:", Now())
.Range("O4:P4") = Array("Sender:", OutApp.session.accounts.It
.Protect
End With
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs (sFullPath)
Application.DisplayAlerts = True
Application.ScreenUpdating
On Error Resume Next
With OutMail
.to = "HRTimesheets@yourcompany.
.Subject = sFileName
.Attachments.Add ActiveWorkbook.FullName
.Display
'.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
ActiveWorkbook.Close SaveChanges:=True
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hopefully you found something to fix your code there.