I am trying to covert the following piece of VB code to use in COMatePlus and have become stuck at adding a paragraph at the end of the document.
Code: Select all
'Insert a paragraph at the end of the document.
'** \endofdoc is a predefined bookmark.
Set oPara2 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks("\endofdoc").Range)
oPara2.Range.Text = "Heading 2"
oPara2.Format.SpaceAfter = 6
oPara2.Range.InsertParagraphAfter
oPara2
2147614729
Type mismatch
Code: Select all
IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"
Define.COMateObject oWord, oDoc, oTable, oPara1, oPara2, oPara3, oPara4, oRng, oShape, oChart, oBookMark
Define pos.d
oWord = COMate_CreateObject("Word.Application")
If oWord
oWord\SetProperty("Visible = #True")
oDoc = oWord\GetObjectProperty("Documents\Add")
;Insert a paragraph at the beginning of the document.
oPara1 = oDoc\GetObjectProperty("Content\Paragraphs\Add")
oPara1\SetProperty("Range\Text = 'Heading 1'")
oPara1\SetProperty("Range\Font\Bold = True")
oPara1\SetProperty("Format\SpaceAfter = 24")
oPara1\SetProperty("Range\InsertParagraphAfter")
;Insert a paragraph at the end of the document.
oBookMark = oDoc\GetObjectProperty("Bookmarks('\endofdoc')\Range")
If oBookMark
Else
Debug "oBookMark"
Debug COMate_GetLastErrorCode()
Debug COMate_GetLastErrorDescription()
EndIf
oPara2 = oDoc\GetObjectProperty("Content\Paragraphs\Add(" + Str(oBookMark) + " As Long)")
If oPara2
oPara2\SetProperty("Range\Text = 'Heading 2'")
oPara2\SetProperty("Format\SpaceAfter = 6")
oPara2\SetProperty("Range\InsertParagraphAfter")
Else
Debug "oPara2"
Debug COMate_GetLastErrorCode()
Debug COMate_GetLastErrorDescription()
EndIf
; Free up the COM Objects
oWord\Release()
oDoc\Release()
oPara1\Release()
oBookMark\Release()
Else
MessageRequester("COMatePlus - Test", "Couldn't create the oWord object!")
EndIf
Can anyone who has used COMatePlus help me with this?
I'm using PB 5.60 Beta 6 x64 on Windows 10 x64.