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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automate Excel from Access with arguments

Status
Not open for further replies.

TimSzrejter

Programmer
Feb 13, 2001
18
0
0
US
I have an Excel 97 file which contains some VBA procedures. From Access, I am able to open Excel and open the file that contains the procedures. What is the correct way to call this procedure inside the Excel file from MS Access 97 and also pass arguments to the procedure.

Thanks for any help!

Tim Szrejter
 
Is this what you mean. I use object to aviod version incompatibilties and, "late binding" isn't really a performance handicap unless you're calling Excel "a bunch".
Dim objExcel as object
Set objExcel = ' however you opened it
objExcel.procname arg1, arg2, arg3, ....
strValue = objExcel.functionorpropertyname(arg1, arg2, arg3,...)

objExcel.Property = arg1
 
I just got it working though it didn't work quite the way you showed.

objExcel.Run "procname", "arg1"

Not sure about the function cause I didn't need to return anything so I didn't even try that one out.

Thanks!!
 
Ok. I forgot that the Procs and Functions are in the WorkBook. This works as a VBS script.

Code:
Dim objWk
Dim ObjXL
Set objWk = getobject("D:\tclooko\tclook.xls")
Set objXL = objWk.Application
objxl.visible = true
objWk.DisplayWKMsg "Executed objwk"
objWk.Close false
objxl.Quit
With this Procedure in the Workbook
Code:
Public Sub DisplayWKMsg(strMsg As String)
    MsgBox strMsg
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top