# Set Shell = CreateObject("Shell.Application")



## michaeldh

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.


----------



## Legacy 98055

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


----------



## DocAElstein

Hi, ......

 I found the explanation in Post #2 very concise, clear and helpful. I have used it in an example of an alternative solution to a Thread to get at a File. This may be a useful simple demonstration example for anyone stumbling over this Thread after a sesarch concerning 
CreateObject("Shell.Application")
http://www.mrexcel.com/forum/excel-questions/918955-macro-code-opening-excel-file.html#post4427500
Alan


----------

