Passing argument to excel

  • Thread starter Thread starter rci
  • Start date Start date
R

rci

Hi all...

Interesting task here...

I am using a Visual Basic app (NOT excel) to send a Shell() command that
launches an excel sheet:

"C:\MySheets\Go.xls"

Windows finds Excel, loads the Go.xls sheet, and all is well...

Here is the issue: I wish to pass an argument ALONG with this shell command
that can be "seen" by Go.xls

For example, I'd like to have this work:

Result = Shell("C:\Mysheets\Go.xls " & iArgument)

(where iArgument is an integer variable)


A macro in Go.xls would need the iArgument to know what to do...
Is there a way to accomplish this?

Thanks so much!

M
 
Stephen Bullen Posted:
I have a menu item which reads:

"C:\Office95\Office\EXCEL.EXE" "D:\book2.xls" /e/param1/param2

In book2.xls, I have:

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

Sub Workbooks_Open()

Dim s As String, i As Integer

s = GetCommandLine

i = InStr(1, s, "/e")

MsgBox Mid(s, i + 2, 200)

End Sub

When I run it, I get a message box saying "/param1/param2". Works for
Excel 95 and 97. The key is to use the (valid) /e parameter, but tack
on your other parameters afterwards. Note that you can't use spaces in
your parameters, even if they are in strings.
 
AS you are already using VB, there is an easier way than using Shell (I don't
think it allows arbitrary command line arguments):

set xl = CreateObject("Excel.Application")
xl.Workbooks.Open "c:\mysheets\go.xls"
xl.visible = true
xl.Run "xx(78)"
set xl = nothing

where xx is a public macro in a module and 78 is an integer being passed to
it.
 

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

Back
Top