I got an error by yousing your example Code:
This Error happends with MSWord 97.
Line:
If WordApplication\Invoke("Documents\Open('" + Infile + "')") = #S_OK <== ERROR
Greetings Steffen
!Documents\Open Unknown error. (Code : Hex 8002801C). Please report this error code to the author at 'enquiries@nxsoftware.com'
Code: Select all
;/////////////////////////////////////////////////////////////////////////////////
;***COMate*** COM automation through iDispatch.
;*===========
;*
;*Convert a Word document to HTML by Kiffi. http://www.purebasic.fr/english/viewtopic.php?t=35719
;/////////////////////////////////////////////////////////////////////////////////
IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"
#wdFormatHTML = 8
#wdFormatFilteredHTML = 10
Procedure GetFormatHTML(WordApplication.COMateObject)
; inspired by Joost Schwider
; http://vb-tec.de/wordhtml.htm
Protected FileConverter.COMateObject
Protected FileConverters.COMateEnumObject
Protected SaveFormat
Debug WordApplication\GetIntegerProperty("Version")
If WordApplication\GetIntegerProperty("Version") > 8
SaveFormat = #wdFormatHTML
Else
FileConverters = WordApplication\CreateEnumeration("FileConverters")
If FileConverters
FileConverter = FileConverters\GetNextObject()
While FileConverter
If FileConverter\GetStringProperty("ClassName") = "HTML"
SaveFormat = FileConverter\GetIntegerProperty("SaveFormat")
FileConverter\Release()
Break
EndIf
FileConverter\Release()
FileConverter = FileConverters\GetNextObject()
Wend
FileConverters\Release()
EndIf
EndIf
ProcedureReturn SaveFormat
EndProcedure
Procedure ShowErrorIfAny()
If COMate_GetLastErrorCode()
Debug COMate_GetLastErrorDescription()
EndIf
EndProcedure
Procedure Doc2Html(Infile.s, OutFile.s)
Protected ReturnValue
Protected WordApplication.COMateObject
ReturnValue = #False
If FileSize(Infile) = -1
Debug "file not found"
Else
WordApplication = COMate_CreateObject("Word.Application")
If WordApplication
If WordApplication\Invoke("Documents\Open('" + Infile + "')") = #S_OK
If WordApplication\Invoke("ActiveDocument\SaveAs('" + OutFile + "', " + Str(GetFormatHTML(WordApplication)) + " As Long)") = #S_OK
ReturnValue = #True
Else
Debug "!ActiveDocument\SaveAs"
Debug ShowErrorIfAny()
EndIf
WordApplication\Invoke("Quit(0)")
Else
Debug "!Documents\Open " + COMate_GetLastErrorDescription()
EndIf
WordApplication\Release()
Else
Debug "!WordApplication"
Debug ShowErrorIfAny()
EndIf
EndIf
ProcedureReturn ReturnValue
EndProcedure
;Test.
Define Infile.s = "D:\HwText\SsBriefe\146.sst"
Define OutFile.s = "D:\HwText\SsBriefe\146.sst.doc"
If Doc2Html(Infile, OutFile) = #True
RunProgram(OutFile)
EndIf
Code tags added
23.08.2018
RSBasic