Error in ComMate

Just starting out? Need help? Post your questions and find answers here.
SteffenSperling
User
User
Posts: 12
Joined: Tue Mar 27, 2018 6:16 pm

Error in ComMate

Post by SteffenSperling »

Hi, sorry but the mail came back with error TimeOut:
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
User avatar
Kiffi
Addict
Addict
Posts: 1486
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Error in ComMate

Post by Kiffi »

Hello Steffen,
SteffenSperling wrote:I got an error by yousing your example Code:

Code: Select all

[...]
Define Infile.s  = "D:\HwText\SsBriefe\146.sst"
[...]
With the code in your posting you can convert Word documents to HTML. As far as I know, SST is not an official Word extension.

SST = CertificateStoreFile?

Greetings ... Peter

P.S.: Please use code tags in the future.

Image
Hygge
SteffenSperling
User
User
Posts: 12
Joined: Tue Mar 27, 2018 6:16 pm

Re: Error in ComMate

Post by SteffenSperling »

Hi Peter,

thanks for replay.

".sst" is not the Problem. It's a doc (word) document. and word has no Problems with it.


but for be shure I have tested it whis".doc" it's the same


Greetings Steffen
acreis
Enthusiast
Enthusiast
Posts: 204
Joined: Fri Jun 01, 2012 12:20 am

Re: Error in ComMate

Post by acreis »

No error with this code PB 5.46 32 BIT WORD 2000
User avatar
Fig
Enthusiast
Enthusiast
Posts: 352
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Error in ComMate

Post by Fig »

I got that kind of error because my office was not registered: a splash screen appeared and it locked the Comate functions.
I suggest you check that.
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
Post Reply