Hi guys,
I wrote a VBA on outlook which basically saves an attachment into a folder and then runs a vba code in another excel file that is saved in that folder also. However, it only runs the first vba in the second excel file. For simplicity, i have two codes in the second excel file, first is output Test in cell and then second code is create a new excel workbook and save it in the folder also.
here is the outlook code:
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "C:\Users\KARMAO2\Desktop"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
Call Application_Startup
End Sub
Private Sub Application_Startup()
Dim ExApp As Excel.Application
Dim ExWbk As Workbook
Set ExApp = New Excel.Application
Set ExWbk = ExApp.Workbooks.Open("C:\Users\KARMAO2\Desktop\TESTING MACRO.xlsm")
ExApp.Visible = True
ExWbk.Application.Run "Module1.Test_Open()"
ExWbk.Application.Run "Module1.AddNewWorkbook2()"
ExWbk.Close SaveChanges:=True
End Sub
Here is the code for second excel file
Sub Test_Open()
Range("A1").Value = "Testing"
End Sub
Sub AddNewWorkbook2()
Dim wkb As Workbook
Set wkb = Workbooks.Add
wkb.SaveAs "C:\Users\KARMAO2\Desktop\WorkbookName.xlsm", FileFormat:=52
'52 = xlOpenXMLWorkbookMacroEnabled = xlsm (with macro's in 2007-2013)
wkb.Close SaveChanges:=True
End Sub
Why doesnt my outlook code run both these macros?
Bookmarks