How to convert Word documents to HTML

xiaoxiao2021-03-17  186

DIM Objword

DIM Objdoc

DIM OBJFSO

DIM STRSOURCE

DIM STRTARGET

DIM BBATCH

'Get command line parameters, there are three possible formats: [- s] Source file directory or file to convert to HTML files saved after saving

Function getParams ()

DIM Objarg

IF wscript.Arguments.count> = 2 THEN

IF wscript.Arguments.Item (0) = "-s" or wscript.arguments.Item (0) = "-s" then

Strsource = wscript.Arguments.Item (1)

Strtarget = wscript.arguments.Item (2)

Bbatch = false

Else

Strsource = wscript.Arguments.Item (0)

Strtarget = wscript.Arguments.Item (1)

Bbatch = TRUE

END IF

Else

WScript.quit (1)

END IF

END FUNCTION

Function BatchProcessing ()

DIM Objfolder

DIM Objfile

Dim LPOS

DIM STRFILENAME

LPOS = 0

Set objfolder = objfso.getfolder (strsource)

For Each Objfile in Objfolder.Files

LPOS = INSTR (1, MID (Objfile.Path, Len (Objfile.Path) - 3, 4), "DOC", 1)

IF LPOS> 0 THEN

Strfilename = objfso.getbasename (Objfile.path)

WordInterface objfile.path, strfilename

END IF

NEXT

END FUNCTION

Function SingleProcessing ()

DIM Objfile

Set objfile = Objfso.getfile (strsource)

Strfilename = objfso.getbasename (Objfile.path)

WordInterface objfile.path, strfilename

END FUNCTION

Function WordInterface (StrfileName, FormattedFileName)

Objword.documents.open strfilename

Set objdoc = objword.activedocument

'Stop

'set the title of the document to match the filename

Objdoc.builtindocumentProperties (1) = formattedFileName

'1 = WDPROPERTYTILE IN VBA

Objdoc.saveas Strtarget & "& FormattedFileName &" .htm ", 8

'Objdoc.saveas "C: / DOC2HTML /" & FORMATTEDFILENAME & ".htm", 8on Error ResMe Next

Objdoc.close

END FUNCTION

'Stop

Set objfso = creteObject ("scripting.filesystemobject")

Set objWord = CreateObject ("word.application")

Objword.visible = false

Call getparams

IF bbatch then

Call batChProcessing

Else

Call SingleProcessing

END IF

Objword.quit

Set objword = Nothing

转载请注明原文地址:https://www.9cbs.com/read-129701.html

New Post(0)