IE Automation to Save as File Download from website with LogIn

johnmpc

Board Regular
Joined
Oct 19, 2020
Messages
108
Office Version
  1. 365
Platform
  1. Windows
Hi Guru's,

I have the below code working to automate the download starting process, but i can't for the life of me work out the Methods explained and code provided on several posts relating to the automation of the Save AS Process.
Please would someone kindly Help me.

"C:\Pricelists\Ralawise\" Is the target file location.
RalawisePrice is the desired filename.

I will need it to overwrite or Kill the existing files in the location too.

Thank you.


VBA Code:
Sub RalawiseAIE()


'to refer to the running copy of Internet Explorer
Dim IE As InternetExplorer


'open Internet Explorer in memory, and go to website
Set IE = New InternetExplorer


With IE
        .Visible = True
        .Navigate ("https://shop.ralawise.com/")
        While .Busy Or .ReadyState <> 4: DoEvents: Wend
            
            
      
    With .Document
    If .querySelectorAll("button#login").length > 0 Then
        .getelementbyid("EmailAddress").Value = "John.G@MPCembroidery.co.uk"
        .getelementbyid("Password").Value = "*Password*" 'Not Real Password
        .getelementbyid("login").Click
    
     Else
    End If
    End With
    
    .Navigate ("https://shop.ralawise.com/globalassets/webdatadownloads/distinctsku.zip")
   
    
End With
End Sub
 
So, I thought this was working Perfectly, BUT it seems like it does the download and runs the Automation fine but then gets stuck. doesn't finish. The file is there and correct.

Any ideas?
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
VBA Code:
 NotificationBarTextString = NotificationBarText.GetCurrentPropertyValue(UIA_ValueValuePropertyId)

If i leave it to run for like 10mins, i have to close the IE window and this is the point it has got to. the error shows here because i close the IE window.
 
Upvote 0
VBA Code:
 NotificationBarTextString = NotificationBarText.GetCurrentPropertyValue(UIA_ValueValuePropertyId)

If i leave it to run for like 10mins, i have to close the IE window and this is the point it has got to. the error shows here because i close the IE window.
That line occurs in 2 places in the code. I'm guessing it's the line in this loop which waits until the download has finished:
VBA Code:
        'Find the Notification bar Text element in the Frame Notification Bar pane and wait until it contains " download has completed"
        
        NotificationBarTextString = ""
        Do
            Set NotificationBarText = NotificationToolbar.FindFirst(TreeScope_Children, NameAndType)
            DoEvents
            Sleep 200
            If Not NotificationBarText Is Nothing Then
                NotificationBarTextString = NotificationBarText.GetCurrentPropertyValue(UIA_ValueValuePropertyId)
            End If
            If DebugLevel >= 1 Then Debug.Print Time; NotificationBarTextString
        Loop Until InStr(NotificationBarTextString, sText_Download_has_Completed)
That code is waiting for the exact text " download has completed" to appear in the Notification bar at the bottom of the IE window.

What is the text that appears in your IE's Notification bar when the download has completed? What is the size of the file you're downloading?
 
Upvote 0
That line occurs in 2 places in the code. I'm guessing it's the line in this loop which waits until the download has finished:
VBA Code:
        'Find the Notification bar Text element in the Frame Notification Bar pane and wait until it contains " download has completed"
       
        NotificationBarTextString = ""
        Do
            Set NotificationBarText = NotificationToolbar.FindFirst(TreeScope_Children, NameAndType)
            DoEvents
            Sleep 200
            If Not NotificationBarText Is Nothing Then
                NotificationBarTextString = NotificationBarText.GetCurrentPropertyValue(UIA_ValueValuePropertyId)
            End If
            If DebugLevel >= 1 Then Debug.Print Time; NotificationBarTextString
        Loop Until InStr(NotificationBarTextString, sText_Download_has_Completed)
That code is waiting for the exact text " download has completed" to appear in the Notification bar at the bottom of the IE window.

What is the text that appears in your IE's Notification bar when the download has completed? What is the size of the file you're downloading?
There isn't a message box that i can see. There is a virus scanner thing and that has a click box that says view download. But that disappears on its own. I'm assuming in your code. Nothing After that.

File is 8MB
 
Upvote 0
That line occurs in 2 places in the code. I'm guessing it's the line in this loop which waits until the download has finished:
VBA Code:
        'Find the Notification bar Text element in the Frame Notification Bar pane and wait until it contains " download has completed"
       
        NotificationBarTextString = ""
        Do
            Set NotificationBarText = NotificationToolbar.FindFirst(TreeScope_Children, NameAndType)
            DoEvents
            Sleep 200
            If Not NotificationBarText Is Nothing Then
                NotificationBarTextString = NotificationBarText.GetCurrentPropertyValue(UIA_ValueValuePropertyId)
            End If
            If DebugLevel >= 1 Then Debug.Print Time; NotificationBarTextString
        Loop Until InStr(NotificationBarTextString, sText_Download_has_Completed)
That code is waiting for the exact text " download has completed" to appear in the Notification bar at the bottom of the IE window.

What is the text that appears in your IE's Notification bar when the download has completed? What is the size of the file you're downloading?

I found a setting to turn on notifications for when downloads are complete. Works now.

THanks
 
Upvote 0
I found a setting to turn on notifications for when downloads are complete. Works now.

Thanks for the update. I was aware that the code requires the IE setting 'Notify when downloads complete' to be ticked, and there is comment to that effect in the code.

I've now improved the UIAutomation to work regardless of that setting:

 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top