Running an opened Excel macro from VB

ddid used Ask the Experts™
I show some examples of how to run a Excel macro from VB but,
all the samples had the line:
Set Wb = xl.Workbooks.Open("file.xls")
I need to run the macro when the Excel file is already open
and not to open a new Excel workbook

I will open the Excel file once and the VB will run this macro again and again
please help me with that
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You can use the GetObject() function to return a reference to an open Excel application.  Something like this...

Dim objExcel As Excel.Application
Dim objWorkbook as Excel.Workbook

Set objExcel = GetObject(, "Excel.Application")
Set objWorkbook = objExcel.Workbooks("file.xls")
... additional code ...



is there a way that I can ask if the workbook is open
if not, open it
if open, getObject

This is what I use...

Set objExcel = GetObject(, "Excel.application")
If objExcel Is Nothing Then
    set objExcel = CreateObject("Excel.Application")
End If

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial