- What are the principles of converting MS Office VBA code into Xojo VBA code; any differences?
- The principles of converting vbscript into MS Office VBA/Xojo VBA?
- I have a working vbscript code (see below) that replaces a piece of text in a doc file with an image and a failed attempt to do the same using Xojo VBA.
vbscript:
Dim oWord
Err = 0
On Error Resume Next
'Set oWord = GetObject("Word.Application")
Set oWord = CreateObject("Word.Application")
oWord.Visible = TRUE
oWord.displayalerts=false
oWord.Application.ScreenUpdating = False
oWord.Documents.add("C:\\tpl.dotx")
Set objSelection = oWord.Selection
Set objShape = objDoc.Shapes
'oWord.ActiveWindow.ActivePane.View.ShowAll = True
oWord.Selection.Find.Text = "<<image>>"
oWord.Selection.Find.Forward = True
oWord.Selection.Find.Wrap = wdFindContinue
oWord.Selection.Find.Format = False
oWord.Selection.Find.MatchCase = False
oWord.Selection.Find.MatchWholeWord = False
oWord.Selection.Find.MatchWildcards = False
oWord.Selection.Find.MatchSoundsLike = False
oWord.Selection.Find.MatchAllWordForms = False
while oWord.Selection.Find.Execute = True
'objSelection.TypeText "TEXT"
'oWord.Selection.objShape.AddPicture("C:\\this.png")
Set pic = oWord.Selection.InlineShapes.AddPicture("C:\\this.png") ' FileName:="C:\\IMAGE\\myimage.TIF", LinkToFile:=False, SaveWithDocument:=True
pic.Height = 100
pic.Width = 200
Wend
oWord.Application.ScreenUpdating = True
'oWord.ActiveWindow.ActivePane.View.ShowAll = False
'oWord.Documents(1).Protect wdAllowOnlyFormFields, True
'oWord.ActiveDocument.Save
VBA
Dim word as WordApplication
Dim doc as WordDocument
word = New WordApplication
word.visible = True
doc = Word.Documents.Add("c:\\tpl.dotx", true)
Dim find as WordFind
find = word.selection.find
Find.Text="<<image>>" //Find field
Find.Replacement.Text=""
Find.Forward = True
Find.Wrap = 1
Find.Format = False
Find.MatchCase = False
Find.MatchWholeWord = False
Find.MatchWildcards = False
Find.MatchSoundsLike = False
Find.MatchAllWordForms = False
Dim oleparam as New OLEParameter
oleparam.value = office.wdReplaceAll
oleparam.Position = 11
find.execute oleparam
'word.selection.GoTo_ (,,,)
word.selection.Range.InlineShapes.AddPicture ("c:\\this.png")