View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Keith Willshaw Keith Willshaw is offline
external usenet poster
 
Posts: 170
Default Command Line Arguments


"Michael" wrote in message
...
I have an Excel Workbook that, when opened, runs a
particular macro. The macro requires a few arguments from
the user, in order to run. Rather than have the user
specify them as the macro is running, I'd like to have the
user specify them when they open the Workbook (from the
command line). Is there a way to specify command line
arguments to Excel, and if so, how can I access them from
a macro? Thanks.


You cant use the command line arguments since Excel treats all command line
parameters (other than option switches) as names of files it should open.

You could use VB6 or VBscript to automate Excel and then run the
macros with the required data using the Application.Run syntax

Sub Main
Dim objExcel As Object
Set objExcel = CreateObject( "Excel.Application")
objExcel.application.workbooks.open "c:\YourDirectory\YourWorkBook.XLS"

' run macro from workbook
objExcel.application.Run ("YourWorkbook.XLS!.Yourmodule.YourMacro"
,YourArg1, YourArg2)

Set objExcel = Nothing 'clear object from memory

End Sub