running macro function or OLEObjects(buttons) from within VB

bauey
03-19-2003, 06:04 PM
need to know how to make my VB program be able to access macro functions or run OLEobjects (specifically buttons) programatically. Let's say there is a function Add_Click() in the excel file...I want to access this function when I open the excel file from within VB...Is this thing possible?

Wamphyri
03-19-2003, 07:44 PM
need to know how to make my VB program be able to access macro functions or run OLEobjects (specifically buttons) programatically. Let's say there is a function Add_Click() in the excel file...I want to access this function when I open the excel file from within VB...Is this thing possible?
Assuming the proper sacrifices are made to the VBA God then yes.

When you open the excel file you can use the Run method of the Application object to run macros.

BTW the proper scarifice to the VBA God consists of sending a large meat lovers pizza to my appartment. ;)

bauey
03-20-2003, 06:41 PM
used the Run method already....didn't work...or I probably mesed it up...hmmm....how do you use the Run method anyway? Isn't it supposed to be used only with macros that are saved in .XLM (or something?)?

My problem is an Excel file with some code on it's "Sheet 1". Let's say it has an OLEObject (a button) that when clicked runs the function Add_Click().

I want my VB program to open that Excel file programatically to process the function Add_Click() OR simulate clicking the OLEObject so that it runs the Add_Click() function.

Wamphyri
03-20-2003, 07:09 PM
The code that you want to run should be in a module of the excel workbook (not the Sheet1,Sheet2 or ThisWorkbook modules an actual module)
Then a simple

Sub MyRun()
'Runs MySub in Book1.xls
Application.Run ("Book1.xls!MySub")
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum