0

我正在尝试在 Internet Explorer 8 和 9 中创建一个工具栏。其主要功能是在单击图标时启动内部产品并相应地转换文档。但是,我在使用 mshtml.HTMLDocument 时遇到了一些困难。请查看我的代码并提供建议。

感谢您的帮助

' Get the hWnd value of the IE window that the macro button was clicked within
    myhWnd = GetForegroundWindow()
    MsgBox(myhWnd)
    ' for all IE window within the shell window, by the way this
    ' includes Windows Explorer as well as IE windows!

    Dim IE As New SHDocVw.InternetExplorer
    Dim SWs As New SHDocVw.ShellWindows

    For Each IE In SWs
        Doc = IE.Document  ' Set the active document

        Functions.OutputDebugString("setting active document for printing using set Doc in main")
        If TypeOf IE.Document Is mshtml.HTMLDocument Then ' if the document is IE then proceed because EXPLORER window returns in the same group - (This is where I'm having trouble. It keep saying 'Document is not an HTML)
            MsgBox("I'm here")
            If (IE.HWND = myhWnd) Then  ' ENABLE IT AFTER TESTING

                Functions.OutputDebugString("JOB SUBMITTED TO QUEUE NOW. PLEASE WAIT.DO NOT CLICK BUTTON AGAIN TO INCREASE SPEED OF OPERATION...")
                IE.StatusText = "JOB SUBMITTED TO QUEUE NOW. PLEASE WAIT.DO NOT CLICK BUTTON AGAIN TO INCREASE SPEED OF OPERATION..."

                Functions.OutputDebugString("Verifying if the page is still downloading or not.. Do not process if its still downloading, wait in loop for 500 mili seconds")
                If Not (IE.Busy = True) Then ' if IE is not currently downloading page then proceed
loopBackfromBusy:
                    Functions.OutputDebugString("Check in registry about exclusing    access to printer")
                    processFlag = saveFileName(IE.LocationName, Doc.url) ' pass the    document URL to give user more informative error messages.
                    Functions.OutputDebugString("Form_Load() - process flag = ")
                    If processFlag = True Then ' if no other window is printing then   proceed

                        Functions.OutputDebugString("FILE SUBMITTED FOR PRINTING in   form load")
                        IE.StatusText = "FILE SUBMITTED TO PRINTER FOR PRINTING. DO NOT CLICK BUTTON AGAIN AND WAIT FOR OPERATION FINISH..."

                        Functions.OutputDebugString("Initializing printer settings using initializeValues()")
                        intilizeValues(Doc.title) ' initialize printer settings and set everything ready for printer

                        DefaultPrinter = Printer.PrinterName ' store current default printr name
                        MsgBox(PrinterName)
                        Functions.OutputDebugString("Changing current default printer to Print Driver.. Note that this name is case sensitive and must be available on user machine or this software will not work correctly...")
                        SetDefaultPrinterMyWinNT(PrinterName) ' set the default printer to KC

                        Functions.OutputDebugString("Fired printing using default IE command")
                        IE.ExecWB(17, 0) '.... print the document silently

 Else
            MsgBox("Document is not an HTML document")
End If

问题就在这里:如果 TypeOf IE.Document 是 mshtml.HTMLDocument。它一直说文档不是 HTML 文档。我将不胜感激任何建议或建议。

更新 :

已将 If 条件更改为 If IE.Name = "Windows Internet Explorer" Then If (IE.HWND = myhWnd) Then MsgBox(IE.locationURL)作业已提交……”

4

1 回答 1

0

我决定不通过这个 If TypeOf IE.Document Is mshtml.HTMLDocument 进行检查。如果 IE.Name = "Windows Internet Explorer" 这行得通

于 2013-08-20T16:29:52.520 回答