Excel VBA vbscript error - cannot access the file because its being used by another process

Viewed 44

I am trying to execute VBA code to refresh the query connections in my Excel file. When I run the vbscript, I get the error "cannot access the file because its being used by another process". How do I need to change the vbscript so that I can refresh the connections in C:\Users\PlannerCounts.xlsm

'Input Excel File's Full Path
  ExcelFilePath = "C:\Users\PlannerCounts.xlsm"

'Input Module/Macro name within the Excel File
  MacroPath = "Module1.UpdatingExternalCons"

'Create an instance of Excel
  Set ExcelApp = CreateObject("Excel.Application")

'Do you want this Excel instance to be visible?
  ExcelApp.Visible = True  'or "False"

'Prevent any App Launch Alerts (ie Update External Links)
  ExcelApp.DisplayAlerts = False

'Open Excel File
  Set wb = ExcelApp.Workbooks.Open(ExcelFilePath)
 
'Execute Macro Code
  ExcelApp.Run MacroPath

'Save Excel File (if applicable)
  wb.Save

'Reset Display Alerts Before Closing
  ExcelApp.DisplayAlerts = True

'Close Excel File
  wb.Close

'End instance of Excel
  ExcelApp.Quit

'Leaves an onscreen message!
  MsgBox "Your Automated Task successfully ran at " & TimeValue(Now), vbInformation
0 Answers
Related