View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Edmund Edmund is offline
external usenet poster
 
Posts: 62
Default Passing argument from cmd.exe to Excel VBA

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
--
Edmund
(Using Excel XP)