Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

https://stackoverflow.com/questions/48949738/run-vbscript-code-in-a-batch-file

<!-- : Begin batch script
@ECHO OFF
CLS

cscript //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 --->
<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 > 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>
  • No labels