0

I would like to write a macro to click the print icon (Alt+P) within print preview window in IE11. I thought of using FindWindow, FindWindowEx, SendMessage and PostMessage functions. But when I checked the window info, there seemed to be no button for clicking the print icon.Print Preview Window Info

Wherever I click within the window, it displays only InternetExplorer_TridentDlgFrame in Class. So how should I click the print icon?

I do not want to use Sendkeys or to perform mouse click based on the location as I would be using this macro in different systems.

So is there any suitable way to do this? Any ideas will be very useful. Thanks in advance.

Aprnaa
  • 13
  • 5

1 Answers1

0

try this code

see here for details https://msdn.microsoft.com/en-us/library/aa752117(v=vs.85).aspx

Option Explicit

Sub printIE()

    Const OLECMDID_PRINT = 6            ' declarations needed for late binding only if mnemonics are desired in ExecWB command
    Const OLECMDID_PRINTPREVIEW = 7

    Const OLECMDEXECOPT_DODEFAULT = 0
    Const OLECMDEXECOPT_PROMPTUSER = 1
    Const OLECMDEXECOPT_DONTPROMPTUSER = 2
    Const OLECMDEXECOPT_SHOWHELP = 3

    Dim IE As Object                    ' late binding

'   Dim IE As InternetExplorer          ' early binding ... reference microsoft internet controls

    Set IE = CreateObject("InternetExplorer.Application")

'   IE.Visible = True
    IE.navigate ("google.co.in")

    Do Until IE.ReadyState = 4
    Loop

    IE.ExecWB OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_DONTPROMPTUSER

'   IE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER

End Sub
jsotola
  • 2,238
  • 1
  • 10
  • 22
  • I can't use this code as I am doing only webpage automation. I can't change the source code where it is already specified as IE.ExecWB 7,1 – Aprnaa Sep 18 '17 at 01:22
  • what exactly are you doing? which programming language are you using? please post the code that you are using, if possible – jsotola Sep 18 '17 at 02:36
  • I have a webpage with manuals. I have to use vba & IE to convert those to pdf. There is a print button within the webpage, clicking which will open the print preview window with user prompt. – Aprnaa Sep 18 '17 at 03:03
  • It is an intranet site so I can't share/modify the source code – Aprnaa Sep 18 '17 at 03:04
  • examine the print button (right click ... inspect). it may have the link to the actual URL of the manual – jsotola Sep 18 '17 at 03:13
  • The print button code calls ie.execwb(7,1) to the current page. The page has an URL but the serial numbers in it keep changing..so can't use it – Aprnaa Oct 04 '17 at 01:34
  • the serial number may be someplace else on the page – jsotola Oct 04 '17 at 06:03
  • someplace else? – Aprnaa Oct 04 '17 at 12:30
  • look for it in the html – jsotola Oct 04 '17 at 19:21