I am trying to insert an Image into a Word document that I have created with ComatePlus.
I can get the image in via Copy and Paste but I can not locate the Image in the right spot.
I have also tried insert the image from a file , that also works but I can only put it at the top of the Doc.
Here is the simplified version of the code. You can use any of your own image files to test.
Code: Select all
UsePNGImageDecoder()
UsePNGImageEncoder()
IncludePath "C:\programs\"
XIncludeFile "COMatePlus.pbi"
Global DirApp.s = "C:\DDLS Apps\_DEV\HISTO SRS\"
result = LoadImage(53, DirApp.s + "Images\2063 - Image.png")
SetClipboardImage(53)
File$ = DirApp.s + "Images\2063 - Image.png"
Define.COMateObject oWord, oDoc, oRange, oPara0, oPara1, oPara2, oPara3
Define.COMateObject oPara4, oPara5, oPara6, oPara7
oWord = COMate_CreateObject("Word.Application")
If oWord
If oWord\SetProperty("Visible = #true") = #S_OK
oDoc = oWord\GetObjectProperty("Documents\Add")
If oDoc
oRange = oDoc\GetObjectProperty("Bookmarks('\endofdoc')\Range")
If oRange
oPara0 = oDoc\GetObjectProperty("Content\Paragraphs\Add")
If oPara0
oPara0\SetProperty("Range\Font\Bold = #True")
oPara0\SetProperty("Range\Font\Name = 'Arial'")
oPara0\SetProperty("Range\Font\Size = 15")
oPara0\SetProperty("Range\Text = '"+
"Subject: Special Stain/Re-cut Request " + "'")
oPara0\SetProperty("Format\SpaceAfter = 6")
oPara0\SetProperty("Format\SpaceBefore = 0")
oPara0\Invoke("Range\InsertParagraphAfter()")
EndIf
oRange\Release()
EndIf
String.s = #LFCR$ + "Hello Histology Lab" + #LFCR$ +
"Could you please arrange the following request." + #CR$ +
"Special Stain/Re-cut Request :" + #LFCR$ + "======================"
oRange = oDoc\GetObjectProperty("Bookmarks('\endofdoc')\Range")
If oRange
oPara1 = oDoc\GetObjectProperty("Content\Paragraphs\Add")
If oPara1
oPara1\SetProperty("Range\Font\Bold = #False")
oPara1\SetProperty("Range\Font\Name = 'Arial'")
oPara1\SetProperty("Range\Font\Size = 14")
oPara1\SetProperty("Range\Text = '" + String.s + "'")
oPara1\SetProperty("Format\SpaceAfter = 0")
oPara1\SetProperty("Format\SpaceBefore = 0")
oPara1\Invoke("Range\InsertParagraphAfter()")
EndIf
oRange\Release()
EndIf
String.s = "*** URGENT REQUEST *** " + #CR$ + "======================" + #CR$
oRange = oDoc\GetObjectProperty("Bookmarks('\endofdoc')\Range")
If oRange
oPara2 = oDoc\GetObjectProperty("Content\Paragraphs\Add")
If oPara2
oPara2\SetProperty("Range\Font\Bold = #False")
oPara2\SetProperty("Range\Font\Name = 'Arial'")
oPara2\SetProperty("Range\Font\Size = 14")
oPara2\SetProperty("Range\Text = '" + String.s + "'")
oPara2\SetProperty("Format\SpaceAfter = 0")
oPara2\SetProperty("Format\SpaceBefore = 0")
EndIf
oRange\Release()
EndIf
String.s = #CR$ + "-------------------------------------------------------------"
oRange = oDoc\GetObjectProperty("Bookmarks('\endofdoc')\Range")
If oRange
oPara3 = oDoc\GetObjectProperty("Content\Paragraphs\Add")
If oPara3
oPara3\SetProperty("Range\Font\Bold = #Fasle")
oPara3\SetProperty("Range\Font\Name = 'Arial'")
oPara3\SetProperty("Range\Font\Size = 14")
oPara3\SetProperty("Range\Text = '" + String.s + "'")
oPara3\SetProperty("Format\SpaceAfter = 0")
oPara3\SetProperty("Format\SpaceBefore = 0")
oPara3\Invoke("Range\InsertParagraphAfter()")
EndIf
oRange\Release()
EndIf
String.s = ""
String.s = "Special Stain Request." + #CR$
String.s = String.s + "Re Cut Request." + #CR$
String.s = String.s + "Re Cut and Stain Request." + #CR$
String.s = String.s + "Re Scan Request." + #CR$
String.s = String.s + "-------------------------------------------------------------" + #CR$
oRange = oDoc\GetObjectProperty("Bookmarks('\endofdoc')\Range")
If oRange
oPara4 = oDoc\GetObjectProperty("Content\Paragraphs\Add")
If oPara4
oPara4\SetProperty("Range\Font\Bold = #False")
oPara4\SetProperty("Range\Font\Name = 'Arial'")
oPara4\SetProperty("Range\Font\Size = 14")
oPara4\SetProperty("Range\Text = '" + String.s + "'")
oPara4\SetProperty("Format\SpaceAfter = 0")
oPara4\SetProperty("Format\SpaceBefore = 0")
oPara4\Invoke("Range\InsertParagraphAfter()")
EndIf
oRange\Release()
EndIf
oRange = oDoc\GetObjectProperty("Bookmarks('\endofdoc')\Range")
If oRange
oPara5 = oDoc\GetObjectProperty("Content\Paragraphs\Add")
If oPara5
oPara5\Invoke("Application\Selection\Endkey=6") ; } ( PASTE ) works if no more info and Endkey=6
oPara5\Invoke("Application\Selection\Paste") ; }
;oPara5\Invoke("Application\Selection\InlineShapes\AddPicture('" + file$ + "')") ; } puts image at top of page
EndIf
oRange\Release()
EndIf
String.s = #LFCR$ + "========================================" + #LFCR$
oRange = oDoc\GetObjectProperty("Bookmarks('\endofdoc')\Range")
If oRange
oPara6 = oDoc\GetObjectProperty("Content\Paragraphs\Add")
If oPara6
;oPara6\SetProperty("Range\Font\Size = 14") } comment out and it works
; oPara6\SetProperty("Range\Text = '" + String.s + "'") }
EndIf
oRange\Release()
EndIf
oDoc\Release()
EndIf
oWord\Release()
EndIf
EndIf
Does anybody know the correct syntax to use to put the Image anywhere I want.
Cheers
Leo