GetObject referencing worksheet question

romanemul

New Member
Joined
Jul 22, 2016
Messages
35
Hello forum guys.

I want to know what is the way of referencing worksheet within the GetObject function.
I know there are other ways of refering.

On the MSDN documentation there is example of referencing the class and object with the syntax like this.

Code:
[COLOR=#0101FD][FONT=Consolas]Set[/FONT][/COLOR][COLOR=#000000][FONT=Consolas] LayerObject = GetObject([/FONT][/COLOR][COLOR=#A31515][FONT=Consolas]"C:\CAD\SCHEMA.CAD[B]!Layer3[/B]"[/FONT][/COLOR][COLOR=#000000][FONT=Consolas])[/FONT][/COLOR]

so i supposed it to use it like this

Code:
Dim otherwb As Object


Set otherwb = New Excel.Application
Set otherwb = GetObject("C:\myfile.xlsm[B]!Sheet1[/B]")

Workbook opens up but there is an error message saying automation error. Invalid syntax.

Can anyone help me with proper syntax to reference worksheet,objects etc ?

I cant find proper syntax for it.

Thanks in advance
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try...

Code:
    Dim ws As Object    

    Set ws = GetObject("C:\Users\Domenic\Documents\sample.xlsm", "Excel.Sheet").Worksheets("Sheet1")

Hope this helps!
 
Last edited:
Upvote 0
Yep that works.

But how did you find about "Excel.Sheet" class parameter ? I tried "Excel.Worksheet" and few other class parameter variations and that doesn't worked.
 
Upvote 0
It was mentioned in a book by John Walkenbach called Microsoft Office Excel 2007 Power Programming with VBA. I believe the book has been updated, though. I haven't come across any other reference.
 
Upvote 0
Just answering to make this thread complete. All avaliable class names are located in a windows registry under a path

Code:
HKEY_CLASSES_ROOT

As you navigate through the long list of classes you can find many names used as a "class" parameter in a CreateObject and GetObject methods.

Some of them doesnt seems to work untill you dont add a reference to it.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top