Avatar of shieldsco
shieldscoFlag for United States of America asked on

Close Current IE Browser Window after Dowload and Save

I'm using the following code to download files from the internet and save to a location on my computer. I need to close the current browser window after the download (not the application). Thanks


Dim myURL As String

myURL = "https://portal.kkk.kkknet/wps/portal/unauthportal/home/"


Dim HttpReq As Object
Set HttpReq = CreateObject("Microsoft.XMLHTTP")
HttpReq.Open "GET", myURL, False, "zzzz", "zzzz"
HttpReq.send

ShellEx "https://portal.kkk.kkknet/ibmcognos/bi/?pathRef=.public_folders%2FMAS%2FALJ+HQ+Ad+Hoc+Reports%2FPerformance+Goals%FFY19+Aged+Case+Goal+List&format=spreadsheetML&Download=true&prompt=true"


myURL = HttpReq.responseBody
If HttpReq.Status = 200 Then
    Set oStrm = CreateObject("ADODB.Stream")
    oStrm.Open
    oStrm.Type = 1
    oStrm.Write HttpReq.responseBody
    oStrm.SaveToFile CurrentProject.Path & "\" & "FY19 Aged Case Goal List.xlsx", 2 ' 1 = no overwrite, 2 = overwrite
    oStrm.Close


    
End If

Open in new window

Microsoft AccessVBA

Avatar of undefined
Last Comment
shieldsco

8/22/2022 - Mon
John Tsioumpris

A kind of quick and dirty way should be
Dim oServ As Object
Dim cProc As Variant
Dim oProc As Object

Set oServ = GetObject("winmgmts:")
Set cProc = oServ.ExecQuery("Select * from Win32_Process")
For Each oProc In cProc
    If oProc.Name = TheNameOfTheProcessYouAreInterested Then 'iexplore.exe
     
      oProc.Terminate  ' With this command you can kill it
    End If

Open in new window

Maybe ...i don't have time to test it...it would be a good idea to search if you can handle the downloading without IE ..i have found this post that downloads files without the need of a browser
ASKER
shieldsco

Automation error : Set oServ = GetObject("winmgmts:")


Dim oServ As Object
Dim cProc As Variant
Dim oProc As Object



Set oServ = GetObject("winmgmts:")
Set cProc = oServ.ExecQuery("Select * from Win32_Process")
For Each oProc In cProc
    If oProc.Name = TheNameOfTheProcessYouAreInterested Then 'iexplore.exe
     
      oProc.Terminate  ' With this command you can kill it
    End If

  Next

Open in new window

Capture.JPG
Gustav Brock

Use the DownloadFile function found in my article:

Show pictures directly from URLs in Access forms and reports

Fast and clean.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
John Tsioumpris

Runs fine on me...probably you have some kind of issue Clipboard01.jpgWhich Access ,what OS ?
ASKER
shieldsco

Access 2016 Windows 10
John Tsioumpris

So the Same here...except if you are using Office 64bit.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
shieldsco

32 bit
John Tsioumpris

If you are on 32bit then probably is a permissions issue....or even a problematic update (i have seen something about KB4011051 causing this kind of issues)
Gustav Brock

Why all this trouble to download a file ...
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER
shieldsco

Gustav - error on line :
   Url = "https://portal.cms.cmsnet/ibmcognos/bi/?pathRef=.public_folders%2FMAS%2FALJ+HQ+Ad+Hoc+Reports%2FPerformance+Goals%2FFY19+Aged+Case+Goal+List&format=spreadsheetML&Download=true&prompt=true"

Open in new window


Invalid Outside Procedure
Gustav Brock

That's because the URL seems to be invalid. It hos no domain:

https://portal.cms.cmsnet

Open in new window

ASKER
shieldsco

I get the same error when I run your example
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Gustav Brock

Which error and which example, please?

But as long the URL isn't valid, it is not possible the check this further.

To check, type your URL into a normal browser. If it doesn't open a site or download a file, it cannot be used.
ASKER CERTIFIED SOLUTION
John Tsioumpris

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
shieldsco

Thanks