ronald cole


Actually, I need help coding the "running a macro" part. I have a spreadsheet with a macro called "snafu" on sheet2 that contains a private subroutine called "runme" tied to a button. I just need to script up something that opens the spreadsheet and runs that subroutine and closes the spreadsheet. Sounds simple, huh Six hours of googling and reading the Microsoft Excel Visual Basic Reference could not clue me! I don't think I'm stupid... but I've been wrong before. Here's what I tried:

Set objExcel = WScript.CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("fubar.xls")

' I don't know what to do here. I tried:
' objWorkbook.Sheets(2).Activate
' objExcel.Run("runme")
' but I got an error about not being able to find "runme".
' please clue me in! thanks!!

objWorkbook.Close
objExcel.Quit



Re: need help writing a vbscript to open a spreadsheet and run a subroutine in a macro

bi-lya


Do you open Excel some other application Then move your "runme" in a some Module (not Sheet or Workbook or ClassModule) and make "runme" like Public.
You may not do "objWorkbook.Sheets(2).Activate" for it.






Re: need help writing a vbscript to open a spreadsheet and run a subroutine in a macro

Shasur

Have you tried

objExcel.Run "'fubar.xls'!runme"

(Assuming the macri runme is in fubar.xls)

Cheers
Shasur