1

I have a code to refresh one report using VBScript and run the other batch file to run this refresh.

Below is my VBScript

Set objExcel = CreateObject("Excel.Application")
On Error Resume Next
objExcel.Visible = False
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\Desktop\Test.xlsx")
objWorkbook.RefreshAll
objExcel.DisplayAlerts = True
objWorkbook.Save
objWorkbook.close False
objExcel.Quit

and below is my Batch Script

cscript refresh_excel.vbs

date /T 
Time /T
pause.

Now I need to refresh several Excel reports on different paths. The reports are all located in different paths; some of them are located in the shared folder, which I already test this combination can refresh file in share folder too.

The current solution I have is to create a speared VBScript for each file and run a multi .vbs file using my batch file.

Any more adequate and effective idea of doing this?

BigBen
  • 46,229
  • 7
  • 24
  • 40
nonslearn
  • 29
  • 1
  • 7
  • 2
    Use the `WScript.Arguments` collection to pull the file path from the arguments passed into the script that way the script can be re-used instead of hard coding the path i.e. `cscript refresh_excel "C:\Users\Desktop\Test.xlsx"`. This is in line with a fundamental programming principle - [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) *(Don't Repeat Yourself)*. See [Can I pass an argument to a VBScript (vbs file launched with cscript)?](https://stackoverflow.com/q/2806713) – user692942 May 21 '20 at 14:59
  • Thanks, I am looking to learn more about WScreipt.Arguments. So in this way I can keep only Excel Refresh commend in my VBScript and let my Batch to define multi paths? – nonslearn May 21 '20 at 15:11

0 Answers0