DOS Command Line

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

My batch file opens the following

"C:\Program Files\Microsoft Office\Office10
\excel.exe" "G:\Customers\Vsource\Clarify.xls"


How do I then run the macro "Sheet1.RefreshData" ?
 
Open workbook Clarify.xls and open the VB window (right
click on a sheet tab and select "view code").
In the VB Project Explorer window, under Clarify.xls,
expand "Microsoft Excel Objects" and double click on "This
workbook". Click the drop-down list in the top left hand
corner of the editor window (should read (General) by
default) and select "Workbook".
You will see the following appear in the edit area:

Private Sub Workbook_Open()

End Sub

Whatever code you insert between these lines will be
automatically executed everytime you open the workbook.

Nikos Y.
 
Hi Chris,
From the batch file?
You can't unless you rename the macro Auto_Open() in a general module or
Workbook_Open() in the ThisWorkBook module.
(or call Sheet1.RefreshData from either)
 
Just to expand on some of the useful suggestions already provided:

in G:\Customers\Vsource\Clarify.xls, in the workbook_open, you can call your
macro - you don't have to put the code there.

Private Sub Workbook_Open()
ThisWorkbook.Sheet1.RefreshData
End Sub

Make sure RefreshData has been declared Public.

It might be advisable to move it to a general module rather than have it in
a sheet module. Sheet modules should be used primarily for event related
code.
 
Put a workbook_open event macro in the ThisWorkbook module.
Right click on the small excel logo square to the left of FILE to insert
this

Private Sub Workbook_Open()
your code
end sub
 
Back
Top