Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

https://stackoverflow.com/a/9074483/5079799

No Format
<!-- : Begin batch script
@echo@ECHO offOFF
@clsCLS
::Comments
incscript Batch Script use "::"
::Insert Batch Below and Call Via "%~f0?.wsf"
//nologo "%~f0?.wsf" "C:\tmp\Book1.xlsx" "Sheet2" //job:EXCEL
::Calling VBScript w/ 2 Args!
exit /b
::cscript //nologo "%~f0?.wsf" //job:VBS
::exit /b
PAUSE
----- Begin wsf script --->
<job><script<package>
  <job id="EXCEL">
    <script language="VBScript">
        Dim XLApp
        Dim XLWkbk
        Dim ObjArgs
        Dim strFileName
        Dim strWorkSheetName

        Set ObjArgs = wscript.arguments
        Set XLApp= CreateObject("Excel.Application")
        XLApp.Visible = False
        Set XLWkbk = XLApp.Workbooks.Open(objargs(0))
        If objArgs.count >
'Comments in VBS use ' AKA apostrophe
'Insert VBS Script Here
</script></job> 1 Then
         Set ws = XLWkbk.Sheets(objargs(1))
        ELSE
         Set ws = XLWkbk.Worksheets(1)
        End If
        ws.PrintOut
        XLWkbk.Close False
        XLApp.Quit

        Set XLWkbk = Nothing
        Set XLApp = Nothing
        Set ObjArgs = Nothing
    </script>
  </job>
  <job id="VBS">
    <script language="VBScript">
        'Second Script!
    </script>
  </job>
</package>