HOWTO: Call Microsoft Excel Macros That Take ParametersID: Q153307
|
Using OLE Automation, you can manipulate Microsoft Excel. It is possible to call macro procedures that are stored in Microsoft Excel Workbooks by using the Run method of the Microsoft Excel application object. Microsoft Excel macro procedures that take parameters cause a slight change in the syntax. Included below is a code sample showing how to call a Microsoft Excel macro procedure from Visual Basic.
Option Explicit
Private Sub Command1_Click()
Dim oExcelApp As Object
' Create a reference to the currently running excel application
Set oExcelApp = GetObject(, "Excel.application")
' Make the Excel Application Visible.
oExcelApp.Visible = True
' Run the excel procedure
oExcelApp.run "proc", "David", 30
End Sub
Sub Proc(sParam1 As String, iParam2 As Integer)
MsgBox sParam1 & " is " & iParam2 & " Years Old"
End Sub
For more information about using GetObject, please see the following
article in the Microsoft Knowledge Base:
Q114347
OLE Automation Objects with GetObject and CreateObject
Additional query words:
Keywords : kbinterop kbAutomation kbVBp kbVBp400 kbVBp500 kbVBp600 kbGrpDSO kbOffice2000 kbExcel97 kbexcel2000
Version : WINDOWS:2000,4.0,5.0,6.0,97; :
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: June 3, 1999