passing parameters / arguments to excel

L

LegeDoos

Hi there,

I'm trying to pass parameters to excel, so I can use them in a macro I
wrote.

I found the following on the internet:

Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineA" ()
As String

Sub Test()
Dim X As String
X = GetCommandLine
MsgBox X
End Sub

When I call
excel.exe c:\test.xls parameter
I get the result
"c:\progra~1\micros~2\office11\excel.exe" c:\test.xls
when I call Test. This doesn't work.

Is it possible to read the parameter in a macro and how can I do that?
 
T

Tushar Mehta

Specify an argument for the subroutine as in the untested:

Sub Test(ByVal X As String)
MsgBox X
End Sub

Then, instantiate XL as an ActiveX object. For an example (and you can
find others in the MSKB and elsewhere on the web) see
How to safely instantiate another Office application and close it only
if you started it
http://support.microsoft.com/default.aspx?scid=kb;en-us;555191

Once the XL object is instantiated and is active, open the workbook of
interest, and then use the application's Run method to invoke the macro.

For more on the Run method, see the XL VBA help.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Multi-disciplinary business expertise
+ Technology skills
= Optimal solution to your business problem
Recipient Microsoft MVP award 2000-2004
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top