vba - CreateObject function for "Shell.Application" vs "InternetExplorer.Application" -
i went through post (http://www.mrexcel.com/forum/excel-questions/553580-visual-basic-applications-macro-already-open-ie-window.html). here answer quite intriguing me in code -
sub getie_latebinding() dim ie object createobject("shell.application").windows if .count > 0 ' ie set ie = .item(0) ' or .item(.count - 1) else ' create ie set ie = createobject("internetexplorer.application") ie.visible = true end if ie.navigate "http://support.microsoft.com/kb/q176792/" set ie = nothing end end sub
here createobject() used twice once "shell.application" , other time "internetexplorer.application". first time used reference open windows or active second time used create new browser window.
i tried running following code, results in new ie window each time when there instance open.
public sub trial() dim ie object set ie = createobject("internetexplorer.application") ie.visible = true end sub
i can understand behavior of "internetexplorer.application" - creating new ie application instance each time hence new window. "shell.application" seems fetch open shell application instance , hence, able browse open ie windows. seems bit confusing. missing?
note : guessing related class_initialize() "shell.application". if please me reference.
ie , explorer used same program why shell.application lists open ie windows. doing because used both explorer windows. lucky meets needs.
createobject
used create new object.
getobject(filename)
connects open file, , if not open, opens it.
set xlbook = getobject("c:\users\david candy\documents\super.xls") msgbox xlbook.name
getobject("","shell.application")
connect existing object , fails if it's not running.
set getexcelapp = getobject("", "excel.application") msgbox getexcelapp
don't hung on objects. many objects function libraries shell.application. you created new function library object.
from com help.
**component automation**
mapping visual basic automation
visual basic provides full support automation. following table lists how visual basic statements translate ole apis.
visual basic statement ole apis
createobject (progid)
clsidfromprogid cocreateinstance queryinterface idispatch interface.
getobject (filename, progid)
clsidfromprogid cocreateinstance queryinterface ipersistfile interface. load on ipersistfile interface. queryinterface idispatch interface.
getobject (filename)
createbindctx creates bind context subsequent functions. mkparsedisplayname returns moniker handle bindmoniker. bindmoniker returns pointer idispatch interface. release on moniker handle. release on context.
getobject (progid)
clsidfromprogid getactiveobject on class id. queryinterface idispatch interface.
dim x new interface
find clsid interface. cocreateinstance queryinterface
© microsoft corporation. rights reserved.
Comments
Post a Comment