excel - VBA macro to refresh workbook not working -
i'm trying 'refresh all' (as shown in image below) using macro:
following macro (which written in module1):
sub workbook_refreshall() activeworkbook.refreshall end sub and i'm writing vbscript follows:
'code should placed in .vbs file set objexcel = createobject("excel.application") set book = objexcel.workbooks.open("excel.xlsm", , true) wscript.echo "executing refreshall" objexcel.application.run "'excel.xlsm'!module1.workbook_refreshall" wscript.echo "executing mailing" objexcel.application.run "'excel.xlsm'!thisworkbook.mail" objexcel.displayalerts = false objexcel.application.quit set objexcel = nothing but not refreshing workbook.
you have mismatching of objects , parameters of run.
instead of objexcel.application.run "'excel.xlsm'!module1.workbook_refreshall" should using book object created , in run parameter not need call workbook name again. i.e. book.application.run "module1.workbook_refreshall"
also may want in how creating book object. presumable if vbs file , xlsm file in folder should work. doesn't always.
you may want consider adding beginning of script
set fso = createobject("scripting.filesystemobject") curdir = fso.getabsolutepathname(".") then modify script to
set book = objexcel.workbooks.open( curdir & "\excel.xlsm" ) 
Comments
Post a Comment