0

I am trying to write some VB code in Excel to open one or more document files, typically PDF's, in an internet browser, then cause the browser to print them.

Several document hyperlinks will be listed in a worksheet, and the VB code will step through each one, opening it.

I can get VB to open a series of hyperlinks to documents OK, with each opening in its own tab in the browser. But I can't find out how to get Excel to cause the browser to print the files. Can you suggest some code to get VB to drive the printing by Internet Explorer?

Armali
  • 18,255
  • 14
  • 57
  • 171
  • Please include your code and see my answer here: https://stackoverflow.com/a/52906215/6241235 – QHarr Oct 29 '18 at 09:40

1 Answers1

0

You can try to refer example below.

Option Explicit

Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_DONTPROMPTUSER = 1
Const PRINT_WAITFORCOMPLETION = 2
 
Sub Sample()
 Dim objIE
 
 Set objIE = CreateObject("InternetExplorer.Application")
 
 objIE.navigate "http://www.Microsoft.com/"
 objIE.Visible = 1
 
 Do While objIE.readyState <> 4
  DoEvents
 Loop
 
 objIE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
End Sub

Further, You can try to modify the code as per your requirement.

References:

(1) IWebBrowser2::ExecWB Method

(2) OLECMDID Enumeration

(3) OLECMDEXECOPT Enumeration

Deepak-MSFT
  • 10,379
  • 1
  • 12
  • 19