excel - VBS Doesn't stop running -


i have scheduled task launches vb script in turn runs macro within excel. runs fine (as in results want), however, scheduled task remains 'running' , therefore doesn't start again next morning. vb script follows:

option explicit  dim xlapp, xlbook  set xlapp = createobject("excel.application") set xlbook = xlapp.workbooks.open("c:\mypath\my file.xlsm", 0, true) xlapp.run "mymacro" xlbook.close xlapp.quit  set xlbook = nothing set xlapp = nothing  wscript.quit 

the end of macro (all preceding code work , saves csv output required):

        workbooks("my file.xlsm").activate         worksheets("outputs").select         'activeworkbook.save         'activeworkbook.close - line cause vbs fail after creating csv         application.screenupdating = true         application.displayalerts = true      end sub 

how terminate vb script stop scheduled task running?

unfortunately realized:

    workbooks("my file.xlsm").activate     worksheets("outputs").select     'activeworkbook.save     'activeworkbook.close - line cause vbs fail after creating csv     application.screenupdating = true     application.displayalerts = true 

will give error due fact xlbook object attempting close closed workbook. believe if update vbscript to:

option explicit  dim xlapp, xlbook  set xlapp = createobject("excel.application") set xlbook = xlapp.workbooks.open("c:\mypath\my file.xlsm", 0, true) xlapp.run "mymacro" 'xlbook.close remove line xlapp.quit  set xlbook = nothing set xlapp = nothing  wscript.quit 

and add activeworkbook.save , activeworkbook.close lines, vbscript & excel application should close correctly.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -