I have written a small script that opens an excel workbook, executes a macro, and then saves the workbook. The only problem is that after the macro executes, the save prompt asks if I want to save a copy of my file, not the file itself. If I click on the original file and override the copy save, the prompt just pops up again and asks me to save a copy, without having changed my original file. Does anyone know how to fix this??
Option Explicit
Dim xlApp, xlBook
set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
set xlBook = xlApp.Workbooks.Open("C:\Users\HGAGNE\Desktop\Master.xlsm", 0, False)
xlApp.Run "BatchProcessing"
xlApp.DisplayAlerts = True
Set xlBook = Nothing
Set xlApp = Nothing
Your code (as shown) does not attempt to save or close the open workbook; neither does it attempt to quit the Excel.Application before destroying the object. On a related matter, the second parameter of the Workbooks.Open method (eg UpdateLinks ) does not take 0 as an accepted value.
Option Explicit
Dim xlApp, xlBook
set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
'set xlBook = xlApp.Workbooks.Open("C:\Users\HGAGNE\Desktop\Master.xlsm", UpdateLinks:=2, ReadOnly:=False)'in VBA as this for explanation
set xlBook = xlApp.Workbooks.Open("C:\Users\HGAGNE\Desktop\Master.xlsm", 2, False) 'in VBS
xlApp.Run "BatchProcessing"
'xlBook.Close SaveChanges:=True 'in VBA as this for explanation
xlBook.Close True 'in VBS
xlApp.Quit
'xlApp.DisplayAlerts = True 'not really a need for this
Set xlBook = Nothing
Set xlApp = Nothing
That code was tested as a sub in in an MS Access VBA project and as a VBS script file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.