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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run excel macro automatically w/one command...HOW?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I need to know how to run an excel macro automatically using one command withought opening up the excel program. So that, instead of having to open up the excel work environment and enabling macros and then alt-f8 to run the macro..i could just type the command on the RUN dialog and my macro will work...How would u accomplish this?
 
I don't believe you can run a macro without opening the Excel file. If you can explain what you're trying to accomplish, perhaps I (or we) can give you some info.
techsupportgirl@home.com
Brainbench MVP for Microsoft Word
 
Basically its a VBA program that produces graphs. Since i need to ouput graphs i must use excel unless there is another way around this....i also access the array of elements in excel to sort data. Actually, the data file is ordered in excel format so its easier to manipulate with excel. I don't know if its possible to make a separate program using excel dll's....
 
i need to run an excel macro on the command line...like
i know the command is something to do with excel.exe /m something i just need to know how to run the macro automatically when i run that command line.
 
You don't. You create the macro in Excel and make it an auto-open macro or autorun macro, which I forget the exact name of right now. But you just name the macro Auto_Open or AutoOpen or...well, it IS in the help file! Sorry. Let me know if ya can't find it.
techsupportgirl@home.com
Brainbench MVP for Microsoft Word
 
It has been a long time since I have done this but I believe it is:

excel spreadsheetName macroName /switches
 
1) From a command line, the command could be :

Start "C:\Program Files\Microsoft Office\Office\EXCEL.EXE" C:\AutoGraphFile.xls


2) Within a shortcut, the target could be :

"C:\Program Files\Microsoft Office\Office\EXCEL.EXE" C:\AutoGraphFile.xls

3) A routine within Excel to run automatically when the file is opened would be :

Sub Auto_Open()
Range("A1").Select
ActiveWindow.SelectedSheets.PrintPreview
End Sub


As Dreamboat wrote, the key is naming the routine "Auto_Open"
 
Falcon: Pay no attention to THIS post of mine.

(Actually, JV, didn't someone here say that MS now recommends using the On-open workbook event instead of the Auto_Open these days? I'm not sure why. Have you heard that? Or d'ya think auto_open is still fine like it was?)
techsupportgirl@home.com
Brainbench MVP for Microsoft Word at
 
I wasn't aware ......
I guess I'm one of those who keeps using something until it breaks or I find something better!

How would I use the On-open event ?
 
Alt-F11 to view the visual basic editor (VBE).
Double-click This Workbook in the VBA Project window.

At the top of the code window, it says:

(General) and (Declarations)

Hit the dropdown on General and change it to Workbook. It automatically selects the Workbook_Open event. You'll find other workbook events on the Declarations dropdown.

Maybe this is just in 2000?
techsupportgirl@home.com
Brainbench MVP for Microsoft Word at
 
Oh I see it now, and I have Ex97.
I tested this new way and it works fine of course.
Also, if you have it both ways, they both seem to run upon opening the file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top