We help IT Professionals succeed at work.

Close Current IE Browser Window after Dowload and Save

shieldsco
shieldsco asked
on
90 Views
Last Modified: 2019-03-17
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

Comment
Watch Question

John TsioumprisSoftware & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
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

Author

Commented:
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
CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
Use the DownloadFile function found in my article:

Show pictures directly from URLs in Access forms and reports

Fast and clean.
John TsioumprisSoftware & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

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

Author

Commented:
Access 2016 Windows 10
John TsioumprisSoftware & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
So the Same here...except if you are using Office 64bit.

Author

Commented:
32 bit
John TsioumprisSoftware & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
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)
CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
Why all this trouble to download a file ...

Author

Commented:
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
CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018

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

https://portal.cms.cmsnet

Open in new window

Author

Commented:
I get the same error when I run your example
CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
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.
Software & Systems Engineer
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.