Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing an argument to an Excel procedure

Status
Not open for further replies.

FaneDuru

Technical User
Jul 15, 2002
141
0
16
RO
The next script finds the open session of Excel and call procedure 'MyProc'. It works without passing an argument. I mean the procedure is called if I do not add ', x'. When I tray to pass the argument it looks that it is a sintax probmem in the code...
Code:
  x = "q"
  Set ExcelDeschis = GetObject(,"Excel.application")
  With ExcelDeschis
      .Run "'MyWokbook to be called.xlsm'!myProc",  x
  End With
  Set ExcelExistent = Nothing
Procedure in Excel 'MyWorkbook to be called.xlsm' is:
Code:
Sub myProc(Optional Z as string)
  MsgBox Z & " has been received..."
End Sub
   Can anybode help in order to write the code to prerly pass the argument 'x' to procedure myProc?
   Thanks in advance!
 
I solve it but in a strange manner...
This line does not work (x defined like "q"):
Code:
With ExcelDeschis
      .Run "'MyWokbook to be called.xlsm'!myProc",  x  
End With
But this one works:
Code:
With ExcelDeschis
      .Run "'MyWokbook to be called.xlsm'!myProc",  "q"  
End With
I used this approach:
Code:
With ExcelDeschis
      .Run "'MyWokbook to be called.xlsm'!myProc", chr(34) & x & chr(34) 
End With
and it works. It returns ""q"" to Excel procedure. I can of course 'clean' the marginal quotes and use it but you must admit that its behaviour is strange...
Can anybody explain that?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top