vba - Open an Excel file, run a macro, save it (overwrite) -
i'm trying create .vbs
- opens excel
- runs macro
- saves new information
- quits
this have far:
dim xlapp, xlbook set xlapp = createobject("excel.application") xlapp.displayalerts = false set xlbook = xlapp.workbooks.open("c:\test\test.xlsm", 0, true) xlapp.run "test" xlbook.save xlbook.close false set xlbook = nothing xlapp.quit set xlapp = nothing wscript.echo "upload finished" wscript.quit
i 'upload finished', macro not saved. doing wrong?
the macro putting 1 worksheet another:
sub test() ' ' test macro ' sheets("sheet2").select range("a1:a10").select range("a10").activate selection.cut activesheet.previous.select selection.end(xltoleft).select range("a2").select activesheet.paste end sub
out of curiosity why macro in excel? if controlling excel via object, why not have macro code in there also?
dim xlapp, xlbook set xlapp = createobject("excel.application") xlapp.displayalerts = false set xlbook = xlapp.workbooks.open("c:\test\test.xlsm", 0, true) xlbook.sheets("sheet2").range("a1:a10").cut xlbook.sheets("sheet2").previous.select xlbook.range("a2").paste xlbook.save xlbook.close false set xlbook = nothing xlapp.quit set xlapp = nothing wscript.echo "upload finished" wscript.quit
Comments
Post a Comment