How to close Webpage dialog with VBA

Sense

New Member
Joined
Apr 12, 2018
Messages
6
Hi all,

I am trying to make a macro that opens a site and prints an overview. It should be repeated multiple times so I need all pages to be closed in the end. I can't figure out how to close a Webpage dialog.
I've tried IE.quit but that does not work. Does anybody know how to get this done?

Thanks in advance!

Code:
Private Sub FirstOrder()
    'This will load a webpage in IE
    Dim Browser As InternetExplorer
    Dim i As Long
    Dim Url As String
    Dim IE As InternetExplorerMedium
    Dim objElement As Object
    Dim objCollection As Object
    Dim Shipment As String
    Shipment = ThisWorkbook.Sheets("Orderuitgifte").Range("E18")
    'Create InternetExplorer Object
    Set IE = New InternetExplorerMedium
    'Set IE.Visible = True to make IE visible, or False for IE to run in the background
    IE.Visible = True
 
    'Define URL
    Url = "[URL]https://spl.dhl.com/smcfs/console/BR2shipment.search[/URL]"
    
    'Navigate to URL
    
    IE.Navigate Url
    
    ' Wait while IE loading...
    'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
    Do While IE.ReadyState = 4: DoEvents: Loop   'Do While
    Do Until IE.ReadyState = 4: DoEvents: Loop   'Do Until
    
    Set objCollection = IE.Document.getElementsByTagName("input")
    
    i = 0
    While i < objCollection.Length
        If objCollection(i).Name = "xml:/Shipment/@ShipmentNo" Then
 
            ' Set text for search
            objCollection(i).Value = Shipment
 
        Else
            If objCollection(i).Type = "submit" And _
               objCollection(i).Name = "btnSearch" Then
 
                ' "Search" button is found
                Set objElement = objCollection(i)
 
            End If
        End If
        i = i + 1
    Wend
    
    
    Set objCollection = IE.Document.getElementsByTagName("input")
    
    i = 0
    While i < objCollection.Length
        If objCollection(i).Name = "xml:/Shipment/@ShipmentNo" Then
 
            ' Set text for search
            objCollection(i).Value = Shipment
 
        Else
            If objCollection(i).Type = "submit" And _
               objCollection(i).Name = "btnSearch" Then
 
                ' "Search" button is found
                Set objElement = objCollection(i)
 
            End If
        End If
        i = i + 1
    Wend
    
    objElement.Click    ' click button to search
    
    
    ' Wait while IE loading...
    'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
    Do While IE.ReadyState = 4: DoEvents: Loop   'Do While
    Do Until IE.ReadyState = 4: DoEvents: Loop   'Do Until
    
    Set objCollection = IE.Document.getElementsByTagName("input")
    
    i = 0
    While i < objCollection.Length
        If objCollection(i).Name = "EntityKey" Then
        
            'Check checkbox
            objCollection(i).Checked = True
        
        End If
        i = i + 1
    Wend

        IE.Document.getElementById("scbutton1").Click
        
        Application.Wait (Now() + TimeValue("00:00:03"))
        
            'IE.Document.getElementById("scbutton1").Click
            
            'Do While IE.ReadyState = 4: DoEvents: Loop   'Do While
            'Do Until IE.ReadyState = 4: DoEvents: Loop   'Do Until
            
            IE.Document.getElementById("scbutton8").Click
            
            IE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
            'Application.Dialogs(xlDialogPrint).Show
    
    IE.Quit
    
    'Unload IE
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing
       
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi all,

I am still trying to find a way to get my macro working. I get stuck on navigating a "webpage dialog". It's a popup screen in which a pdf is shown. when the popup is opened from a webpage, the macro waits. when I close the popup, the macro continues. I want the macro to open the popup, print the pdf and close again.

Is there a way to get this done?
Any help is appreciated.

Code:
        IE.Document.getElementById("scbutton1").Click
        
        Application.Wait (Now() + TimeValue("00:00:03"))
        
            'IE.Document.getElementById("scbutton1").Click
            
            'Do While IE.ReadyState = 4: DoEvents: Loop   'Do While
            'Do Until IE.ReadyState = 4: DoEvents: Loop   'Do Until
            
            IE.Document.getElementById("scbutton8").Click
            
            IE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
            'Application.Dialogs(xlDialogPrint).Show
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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