VBA - 使用 .ExecWB 打印 WebForm 的第二页

VBA - Print 2nd Page of WebForm with .ExecWB

我正在使用 Object.ExecWB 在我的 VBA 代码中打印网页。具体来说,我正在使用这一行(IE 是一个 "Application.InternetExplorer" 对象):

Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
IE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER

它按照打印页面的方式执行,但是,它没有打印正确的页面。

该网页是一个具有相同 URL 的网络表单,我的代码正确地到达了我要打印的正确页面(第二个 "page" 或 "screen" 的形式),但是命令仍然打印第一页。

如果我逐行执行代码,它会打印正确的页面,但是,当我让它自己撕开时,它只打印第一页,即使我可以清楚地看到 IE 导航到打印前的第二页。

我试过将睡眠命令放入代码中,但无济于事。有人有什么想法吗?

为清楚起见,这里是我正在尝试的一些代码片段(代码在 IE.document 上使用了 with 语句):

   'this gets to the correct form page
   .getElementsByName("in_1060_1").item(0).Value = "1"
   .parentWindow.setCursorPosition "400", "HATSForm" 
   .parentWindow.ms "[enter]", "HATSForm"

    IEWait IE 'calls a sub that sleeps when IE is busy or not in readystate
    Sleep 5000

    'I then hit the 'OK' button to get to the 2nd page where the info I need to print is
    .parentWindow.ms "[enter]", "HATSForm"

    'yet it still prints out the first page! Ugh!
    Const OLECMDID_PRINT = 6
    Const OLECMDEXECOPT_DONTPROMPTUSER = 2
    IE.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER

我最终将打印屏幕发送到 Word 并打印了 Word 文档。有点复杂,但最终效果很好。

抱歉,我没有用于让它工作的代码,但它来自以前的工作。