⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convhtml.bas

📁 使用WebBrowser控件作为容器打开Word文档 === === === === === === === 这个源代码演示了使用WebBrowser控件作为容器打开Word文档的操作。需要在工
💻 BAS
字号:
Attribute VB_Name = "ConvHTML"

Option Explicit
' ConvHTML.bas Mar, 2006 contact markb@orionstudios.com
' Function to save a Word Document as HTML programmatically
' Includes workaround for problem discussed in KB Q162132 (see below)
' ====================================================================

Public Function SaveDocAsHTML( _
                Doc As Word.Document, _
                NewFileName As String) As String
'
' Returns full path\name of saved file
'
    On Error GoTo SaveDocAsHTML_Error
    
    Dim Result As String ' default function result = ""
    Dim wrdApp As Word.Application
    Dim lngSaveFormat As Long
    
    Set wrdApp = Doc.Application
    lngSaveFormat = GetHTMLSaveFormat(WordApp:=wrdApp)
    If lngSaveFormat Then   ' File Converter for HTML is available for Save
        Doc.SaveAs FileFormat:=lngSaveFormat, FileName:=NewFileName
        With wrdApp.ActiveDocument
            Result = .Path & "\" & .Name
        End With
    End If
    
SaveDocAsHTML_Exit:
    SaveDocAsHTML = Result
    Exit Function
    
SaveDocAsHTML_Error:
    MsgBox Err.Number & " - " & Err.Description, vbExclamation, "SaveDocAsHTML"
    Resume SaveDocAsHTML_Exit
    
End Function

Private Function GetHTMLSaveFormat(WordApp As Word.Application) As Long
'
' KB Article Q162132 - WD97: Run-time error '5880' Saving as HTML from VBA
'
' Problem occurs when accessing the "HTML" document format
' from the FileConverters collection using a string value
' instead of a numerical value for the index.
'
    On Error GoTo GetHTMLSaveFormat_Exit
    
    Dim Result As Long  ' default function result = 0
    Dim wrdFileConverter As Word.FileConverter
    
    For Each wrdFileConverter In WordApp.FileConverters
        If wrdFileConverter.ClassName = "HTML" Then
            With wrdFileConverter
                If .CanSave Then
                    Result = .SaveFormat
                End If
            End With
            Exit For
        End If
    Next wrdFileConverter
    
GetHTMLSaveFormat_Exit:
    GetHTMLSaveFormat = Result
    
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -