Using a macro to open then print a webpage?

Status
Not open for further replies.

pbroadmeadow

New Member
Joined
Dec 3, 2011
Messages
3
Hello all! I am trying to use a macro in Excel to open a website (the URL is a named range in a worksheet) and then print the web page. I am able to open the webpage with the following code:

Sub View_Tech_Recalls()
Set ie = CreateObject("InternetExplorer.Application")
ie.navigate Range("Recall_URL")
ie.StatusBar = False
ie.Toolbar = True
ie.Visible = True
ie.Resizable = True
ie.AddressBar = False
End Sub

What do I need to add in order to print the open web page?

Thanks for your help!

Paul
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Welcome to the board
Code:
ie.ExecWB 6, 2 'print
Application.Wait (Now + TimeValue("0:00:03")) 'let print finish befor continue

Google ExecWB for more info
 
Upvote 0
Hi Warlock,
I added the line of code you recommended; IE opens to the website but the following error is reported:

Run-time error '-2147221248 (80040100)':
Method "ExecWB of object 'IWebBrowser2' failed

Selecting Debug highlights

Sub View_Tech_Recalls()
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate Range("Recall_URL")
ie.StatusBar = False
ie.Toolbar = True
ie.Visible = True
ie.Resizable = True
ie.AddressBar = False
ie.ExecWB 6, 2 'print
Application.Wait (Now + TimeValue("0:00:03")) 'let print finish befor continue
End Sub

Thanks again for your help.

Paul
 
Upvote 0
We also need to be sure IE is fully loaded before printing.
Code:
Sub View_Tech_Recalls()
    Set ie = CreateObject("InternetExplorer.Application")
    ie.navigate Range("Recall_URL")
    ie.StatusBar = False
    ie.Toolbar = True
    ie.Visible = True
    ie.Resizable = True
    ie.AddressBar = False
    
    
    TimeOutWebQuery = 5
    TimeOutTime = DateAdd("s", TimeOutWebQuery, Now)
    Do Until ie.readyState = 4
        DoEvents
        If Now > TimeOutTime Then
            ie.stop
            GoTo ErrorTimeOut
        End If
    Loop



    ie.ExecWB 6, 2
    Application.Wait (Now + TimeValue("0:00:03"))
    
    

ErrorTimeOut:

    
    Set ie = Nothing
End Sub
 
Upvote 0
No problem at all, you're quite welcome.
Stick around MrExcel and you'l find plenty of tips/tricks!
 
Upvote 0
I am also trying to batch print a series of webpages / URLs that I have in a column in my Excel sheet. The URLs are in column A ... can you provide a bit more of a tutorial? I believe I am having a problem with the range; ie.navigate Range("A1:A7") . I am getting a run time error '13' type mismatch. Thank you in advance.
 
Last edited:
Upvote 0
What about changing this macro to open firefox instead? Can someone give feedback on how to do that?
 
Upvote 0
Hey Warship, following you has gotten me as close as anything so far on my issue. It's much the same as this issue, however, in my case the same failure did not go away. My module is supposed to print a pdf that pulls up in internet explorer. It pulls the pdf up with no issue at all, but then halts at IE.ExecWB 6, 2. It's supposed to print the PDF without prompting the user for any additional input and then close the browser, but this is as far as I've gotten. Here's a the module:

Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_DONTPROMPTUSER = 1
Const PRINT_WAITFORCOMPLETION = 2
Sub Sample(addr As String)
Dim IE As InternetExplorerMedium
Set IE = New InternetExplorerMedium
IE.Navigate addr
IE.Visible = 1

Do While IE.Busy
DoEvents
Loop
IE.ExecWB 6, 2
Application.Wait (Now + TimeValue("0:00:03"))
'OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
ErrorTimeOut:
Set IE = Nothing

End Sub
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,585
Messages
6,120,397
Members
448,957
Latest member
Hat4Life

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