I am trying to open excel file from outlook am using office 2016
I have referenced Microsoft Excel 16.0 Object Library and Microsoft Outlook 16.0 Object Library
My code runs fine in debug mode using F8 without any issues however, it does not run in Run Sub.
My code is as below and I am not getting any error message either.
When I view task manager, I can see Microsoft Excel app has been created, and when I kill it and get into debug option, I see that it is stuck at Workbooks.Open method. Can someone please help?
I have referenced Microsoft Excel 16.0 Object Library and Microsoft Outlook 16.0 Object Library
My code runs fine in debug mode using F8 without any issues however, it does not run in Run Sub.
My code is as below and I am not getting any error message either.
When I view task manager, I can see Microsoft Excel app has been created, and when I kill it and get into debug option, I see that it is stuck at Workbooks.Open method. Can someone please help?
VBA Code:
Sub OpenFile()
Dim xlApp As Excel.Application
Dim xlWs As Excel.Worksheet
Dim xlRange As Excel.Range
Set xlApp = CreateObject("Excel.Application")
Workbooks.Open ("C:\Users\MyUserID\Documents\MyFile.xlsx") '<<<Code is getting stuck here
Set xlWs = ActiveWorkbook.Sheets("Emails")
xlWs.Activate
Set xlRange = xlWs.Range("A1")
xlRange.Activate
ActiveWorkbook.Save
xlApp.Quit
Set xlRange = Nothing
Set xlWs = Nothing
Set xlApp = Nothing
End Sub
Last edited by a moderator: