Set Shell = CreateObject("Shell.Application")

michaeldh

Board Regular
Joined
Jun 11, 2002
Messages
201
Hi Guys,

I have used some awesome programming to solve a problem but just wanted to improve my understanding of what it is doing.

The code is:

Set Shell = CreateObject("Shell.Application")

What is "Shell.Application" doing?

If you could explain I would be most appreciative.

Thanks.

Michael.
:)
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Library Shell32
C:\WINDOWS\system32\SHELL32.dll
Microsoft Shell Controls And Automation

Open up your VBA IDE and set a reference to "Microsoft Shell Controls And Automation"

Now open your object browser and select "Shell32".

Under "Classes", select "Shell"

Note that one of the properties, to the right, is an "Application" property. This property returns an object reference to the windows shell.

When using CreateObject, the registry is searched for a program identifier. You are creating a latebound reference to an application object returned by the "Application" property of the "Shell" object which is contained in the "Shell32" library. :)

Your code, as is, is creating a "IShellDispatch4" object. Depending on your version, this may be IShellDispatch3 or IShellDispatch2. To see the properties and methods of this object, you will need to right click within your object browser and select, "Show Hidden Members".

I am trying to confuse you as best as I can. :)

Anyway, your code and what it is doing will become more clear to you if you early bind. That is, set a reference beforehand so the compiler knows what's up ahead of time... Also, the properties and methods will show up via intellisense as you type and any events will now be available to you as well.

Both return references to a "Shell" object.

Code:
Sub ExampleUsingEarlyBinding()
    Dim MyShellObject As Shell32.shell
    'or
    'Dim MyShellObject As Shell32.IShellDispatch4
    Set MyShellObject = New Shell32.shell
End Sub

Sub ExampleUsingLateBinding()
    Dim ShellApp As Object
    Set ShellApp = CreateObject("Shell.Application")
End Sub
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,215,090
Messages
6,123,061
Members
449,091
Latest member
ikke

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