How to parse one variable to Microsoft Word
SparkOut
SparkOutYNY at gmail.com
Sat Feb 21 12:44:38 EST 2009
OK, I thought that "one field" with "one replacement" would be too simple :)
There are quite a few parameters you can use with the Find method in VBS
automation of Word.
It's a bit tidier to wrap the settings in a "With" structure, and I've
defined a few constants to make it clearer. Note that you could just call
objSelect.Find.Execute with all the parameters defined after the statement,
but it's easier to view it as below. Make sure you keep 10 commas before the
wdReplaceAll parameter.
Dim objWord, objDoc, objSelect, result
on Error Resume Next
Const wdStory = 6
Const wdFindContinue = 1
Const wdReplaceAll = 2
result = "OK"
Set objWord = CreateObject("Word.Application")
If Err <> 0 Then
result = "Error opening Word application"
End If
If result = "OK" Then
objWord.Visible = False
With objWord
Set objDoc = objWord.Documents.Open("<<path to doc>>")
If Err <> 0 Then
result = "Error opening template document"
End If
End With
End If
If result = "OK" Then
Set objSelect = objWord.Selection
objSelect.HomeKey(wdStory)
With objSelect.Find
.Text = "{{replace me}}"
.Forward = True
.MatchWholeWord = True
.Wrap = wdFindContinue
.Format = False
.Replacement.Text = "<<replacement text>>"
.Execute ,,,,,,,,,,wdReplaceAll
End With
objSelect.HomeKey(wdStory)
End If
If result = "OK" Then
objWord.Visible = True
Set objSelect= Nothing
set objDoc = Nothing
Set objWord = Nothing
Else
set objDoc = Nothing
objWord.Close
objWord.Quit
End If
Nhan, Tran Thi Thanh wrote:
>
>
>
> Thanks SparkOut and all of you so much
>
> Because I'm not good in VBS so could you help me check this case: when I
> have more {{replace me}} than one in Template file, VBS just replace one
> {{replace me}} by "<<replacement text>>".
>
> Regards,
>
>
--
View this message in context: http://www.nabble.com/How-to-parse-one-variable-to-Microsoft-Word-tp22133088p22138560.html
Sent from the Revolution - User mailing list archive at Nabble.com.
More information about the use-livecode
mailing list