Automate IE print dialog box without using SendKey

2019-10-17 16:32发布

Is it possible to control the IE browser print dialog box in VBA without using SendKeys?

1条回答
神经病院院长
2楼-- · 2019-10-17 17:13

It is, by using the InternetExplorer object's ExecWB method (see this link for details).

After adding a reference to the Microsoft Internet Controls library to your project, the following example should get you started:

Option Explicit

Sub PrintWebPage()

    Dim ie As InternetExplorer

    Set ie = New InternetExplorer

    ie.Navigate "http://www.google.com/"
    ie.Visible = 1

    'Wait for page to finish loading
    Do While ie.ReadyState <> READYSTATE_COMPLETE
     DoEvents
    Loop

    ie.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER

    MsgBox "Done printing.", vbInformation

End Sub
查看更多
登录 后发表回答