Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default command line excel to run macros


"Anthony Ryan" wrote in message
...
Try this,

Create a batch file with this code: start excel "C:\Test.xls"

/macro=mymacro

or Win95 shortcut with this in the Target line: "C:\Test.xls"
/macro=mymacro


in the Test.xls spreadsheet in a module or the place where you wish to

place
your code
In the declarations section place:
Public Declare Function GetCommandLine Lib "kernel32" Alias
"GetCommandLineA" () As String

Then create the subroutine called Auto_Open() or in the Workbook_Open()
subroutine and place in it:

Dim strCommand as String

' Get the commandline argument
strCommand = GetCommandLine()

' Removes all text before mymacro
strCommand = Right$(strCommand, Len(strCommand) - Instr(1, strCommand,
"/macro=") - 7)

' Removes all text after mymacro
strComannd = Left$(strCommand, Instr(1, strCommand, Chr$(0)) - 1)

' This statements run the macro defined by strCommand in the currently
opened workbook
Application.Run "'" & ThisWorkbook.Name & "'!" & strCommand


I hope you suceed with this as my original code is a little different but

I
used this to control if a addin was to be loaded in or not. If the
spreadsheet was opened by the batch file the commandline was present (the
addin was loaded) and if it was opened in Windows Explorer by
double-clicking it a commandline argument was NOT present (the addin was

NOT
loaded)

Anthony


"baldev" wrote in message
...
does anyone know how to run excel from a command line
incorporating Excel macro eg

Call Excel.exe /macro=mymacro





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use Windows command within Excel macros Tom Excel Discussion (Misc queries) 2 April 20th 10 12:01 AM
Are there command line parameters for Excel? Michael Excel Discussion (Misc queries) 9 August 5th 07 06:29 PM
What are the possible command-line arguments in Excel? d2reason Excel Discussion (Misc queries) 2 June 4th 07 09:39 PM
command line Excel Script [email protected] Excel Discussion (Misc queries) 0 August 22nd 06 01:23 PM
macros from command line Cyberwolf Excel Discussion (Misc queries) 3 July 19th 05 05:35 PM


All times are GMT +1. The time now is 01:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"