windows如何将doc文件转换为其他格式文件

我们需要先下载安装 Microsoft Office Word Add-in For MediaWiki

http://www.microsoft.com/download/en/details.aspx?id=12298

windows将doc文件保存为pdf文件源代码

Option Explicit

Doc2PDF "C:\test.doc"

Sub Doc2PDF( myFile )

    Dim objDoc, objFile, objFSO, objWord, strFile, strPDF

    Const wdFormatDocument                    =  0
    Const wdFormatDocument97                  =  0
    Const wdFormatDocumentDefault             = 16
    Const wdFormatDOSText                     =  4
    Const wdFormatDOSTextLineBreaks           =  5
    Const wdFormatEncodedText                 =  7
    Const wdFormatFilteredHTML                = 10
    Const wdFormatFlatXML                     = 19
    Const wdFormatFlatXMLMacroEnabled         = 20
    Const wdFormatFlatXMLTemplate             = 21
    Const wdFormatFlatXMLTemplateMacroEnabled = 22
    Const wdFormatHTML                        =  8
    Const wdFormatPDF                         = 17
    Const wdFormatRTF                         =  6
    Const wdFormatTemplate                    =  1
    Const wdFormatTemplate97                  =  1
    Const wdFormatText                        =  2
    Const wdFormatTextLineBreaks              =  3
    Const wdFormatUnicodeText                 =  7
    Const wdFormatWebArchive                  =  9
    Const wdFormatXML                         = 11
    Const wdFormatXMLDocument                 = 12
    Const wdFormatXMLDocumentMacroEnabled     = 13
    Const wdFormatXMLTemplate                 = 14
    Const wdFormatXMLTemplateMacroEnabled     = 15
    Const wdFormatXPS                         = 18
    Const wdFormatOfficeDocumentTemplate      = 23
    Const wdFormatMediaWiki                   = 24

    ' 创建FileSystemObject对象
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )

    ' 创建word对象
    Set objWord = CreateObject( "Word.Application" )

    With objWord
        ' 是否打开word窗口
        .Visible = True

        ' 检查doc文件是否存在
        If objFSO.FileExists( myFile ) Then
            Set objFile = objFSO.GetFile( myFile )
            strFile = objFile.Path
        Else
            WScript.Echo "FILE OPEN ERROR: The file does not exist" & vbCrLf
            ' Close Word
            .Quit
            Exit Sub
        End If

        ' 设置保存文件名,设置保存格式
        strPDF = objFSO.BuildPath( objFile.ParentFolder, _
                 objFSO.GetBaseName( objFile ) & ".pdf" )

        ' 打开文档
        .Documents.Open strFile

        ' 将打开的文件设置为活动文档
        Set objDoc = .ActiveDocument

        ' 保存为pdf
        objDoc.SaveAs strPDF, wdFormatPDF

        ' 关闭文档
        objDoc.Close

        ' 退出 Word
        .Quit
    End With
End Sub

要在windows将doc文件保存为html文件,只需将上面的代码中的保存格式.pdf改成 .html
要在windows将doc文件保存为txt文件,只需将上面的代码中的保存格式.pdf改成 .txt
要在windows将doc文件保存为xps文件,只需将上面的代码中的保存格式.pdf改成 .xps

日期:2020-04-11 22:50:12 来源:oir作者:oir