vba - Quit error Internet Explorer Window -
issue : encountering issues closing "premature" internet window has no content yet.
basically if "premature" window open, macro doesn't manage select window i'm interested in, close "premature" window manually, can run code properly. source comes minor error somehow opens except diplaying window doesn't affect rest of code.
tests done :
dim widow object, page_foireuse shdocvw.internetexplorer dim objshell object set objshell = createobject("shell.application") msgbox objshell.windows.count ' msgbox objshell.windows(0).document.title ' msgbox objshell.windows(1).document.title ' msgbox objshell.windows(2).document.title ' msgbox objshell.windows(3).document.title ' msgbox objshell.windows(4).document.title ' msgbox objshell.windows(5).document.title ' msgbox objshell.windows(6).document.title 'for each widow in objshell.windows ' if widow.document.title nothing ' doesn't work ' set page_foireuse = widow ' end if 'next ' 'if objshell.windows(5).document.title nothing 'end if set page_foireuse = objshell.windows(5) page_foireuse.quit msgbox objshell.windows.count
results far :
- when count number of windows in shell, "premature" window counted
- when return location or title of each of counted windows, error when trying return location or title of "premature" window
- the 2 loops tried run @ end didn't work
so question : how can close "premature" window via macro ?
the page on image in question looks strange, no location, no title. try following code, set breakpoint on line set doc = ie.document
, check if doc
not nothing
etc. hth
' add reference microsoft internet controls (shdocvw) ' add reference microsoft html object library ' add reference microsoft shell controls , automation dim ie shdocvw.webbrowser dim doc htmldocument dim shellapp shell32.shell dim windows shdocvw.shellwindows dim window set shellapp = new shell set windows = shellapp.windows each window in windows if not ucase(window.fullname) "*iexplore.exe" goto continue set ie = window set doc = ie.document if doc.title = "" ie.quit exit end if continue: next window
Comments
Post a Comment