Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running Excel macros from an external .vbs file

Status
Not open for further replies.

SlakeB

MIS
Jun 15, 2005
40
0
0
US
Does anyone know how to do this? I have an excel spreadsheet with two buttons on it. Each button triggers a macro. I want an external .vbs file to run those macros without me having to go into excel and push the buttons.
 
Here is what I have so far (something similar worked with Access macros that I was dealing with). It successfully opens the excel document, but it can't find the macro.

Code:
Dim oWSH
Dim retVal

Set oWSH = WScript.CreateObject("WScript.Shell")
retVal = oWSH.Run("excel.exe " & Chr(34) & "D:\Docs\JaydipDB\OutputFiles\testExcelMacros.xls" & Chr(34) & " /x macTest1", 1, True)

I also tried this...still can't find the macro
Code:
Dim oWSH
Dim retVal

Set oWSH = WScript.CreateObject("WScript.Shell")
retVal = oWSH.Run("excel.exe " & Chr(34) & "D:\Docs\JaydipDB\OutputFiles\testExcelMacros.xls" & Chr(34) & " /x testExcelMacros.XLS'!macTest1", 1, True)
 
Something like this ?
Dim oXL, oWB
Set oXL = CreateObject("Excel.Application")
oXL.Visible = True
Set oWB = oXL.Workbooks.Open("D:\Docs\JaydipDB\OutputFiles\testExcelMacros.xls")
oXL.Run "macTest1"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
hey PHV, I used the code below and it worked great. Do you know how to stop the "Do you want to save changes" window from popping up?


Code:
Dim X

Set X=CreateObject("Excel.Application")
Set W=X.Workbooks.Open("D:\Docs\JaydipDB\OutputFiles\testExcelMacros.xls")
X.Run "macTest1"
X.Run "macTest2"
X.Quit

I tried adding "X.Save" before "X.QUIT" but then I got another pop up window asking if I wanted to replace "RESUME.XLW"? Have you encountered this before? The goal is no pop ups.
 
X.DisplayAlerts = False
W.Save
W.Close
X.Quit
Set W = Nothing
Set X = Nothing

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top