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
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

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
Avatar of shieldsco
shieldsco
Flag of United States of America image

ASKER

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
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Use the DownloadFile function found in my article:

Show pictures directly from URLs in Access forms and reports

Fast and clean.
Runs fine on me...probably you have some kind of issue User generated imageWhich Access ,what OS ?
Avatar of shieldsco
shieldsco
Flag of United States of America image

ASKER

Access 2016 Windows 10
So the Same here...except if you are using Office 64bit.
Avatar of shieldsco
shieldsco
Flag of United States of America image

ASKER

32 bit
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)
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Why all this trouble to download a file ...
Avatar of shieldsco
shieldsco
Flag of United States of America image

ASKER

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
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

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

https://portal.cms.cmsnet

Open in new window

Avatar of shieldsco
shieldsco
Flag of United States of America image

ASKER

I get the same error when I run your example
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

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
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of shieldsco
shieldsco
Flag of United States of America image

ASKER

Thanks
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo