cancel
Showing results for 
Search instead for 
Did you mean: 

Referring to an Active Excel Workbook in VBS

Former Member
0 Kudos

I have a .vbs script which works great.  When it runs it opens an Excel workbook in these lines:

Set xcl = CreateObject ("Excel.Application")

Set wbk = xcl.Workbooks.open("C:\Users\Barry\Desktop\Level3\Defects.xlsm")

Set sht - wbk.Sheets("Sheet1")

I want wbk to refer to the active workbook instead (i.e. Set wbk = ActiveWorkbook) but it doesn't like that, gives me "Object Required: ActiveWorkbook"

Please advise


Accepted Solutions (1)

Accepted Solutions (1)

script_man
Active Contributor
0 Kudos

Hi Stuart,

You can try the following:

set wbk = xcl.ActiveWorkbook

Regards,

ScriptMan

Former Member
0 Kudos

Thanks Script Man. I tried that, now I'm getting "Object required: 'wbk'

script_man
Active Contributor
0 Kudos

In this case, one must refer to the existing Excel session.

For example:

set xcl = getObject( , "Excel.Application")

. . .

Regards,

ScriptMan

Former Member
0 Kudos

Works!  Thank you Script Man.

Answers (0)