Passing argument from cmd.exe to Excel VBA

E

Edmund

How can I pass an argument from cmd.exe to an Excel macro?

I tested with VB6 using the below sample & successfully passed Arg1 & Arg2
over to Macro1. But how to do this if I start from cmd.exe instead of VB6?

'======================
' The code in VB6
'======================
Sub Command3_Click()
Dim XL As Object
Dim Ans As String

Set XL = CreateObject("Excel.Application")

With XL
.Workbooks.Open "C:\TheFileContainingMacro1.xls"
Ans = .Run("Macro1", "Value_Of_Arg1", "Value_Of_Arg2")
.Quit
End With
Set XL = Nothing
End
End Sub

'======================
' The code in "C:\TheFileContainingMacro1.xls!Macro1
'======================
Function Macro1(FromExternal_1, FromExternal_Arg2)

With ActiveSheet
.Range("A1") = FromExternal_1
.Range("A2") = FromExternal_2
End With
ActiveWorkbook.Save

End Function


But how to do this if I start from cmd.exe instead of VB6?

Thanks a million
 
H

HatesIT

look up the 'command' function in help. You would then check the args within
your workbook on open sub

hth
 
E

Edmund

Dear Steve,

Thank You is just a simple word, but I mean it very sincerely. "Thank You"
so very much for the extra miles in detailing the explanations step-by-step.
Perfectly clear!
 

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