How to parse one variable to Microsoft Word

Nhan, Tran Thi Thanh nhan.tran at rmit.edu.vn
Sat Feb 21 20:48:53 EST 2009


Dear SparkOut

If I want to find two or more "{{replace me}}" different and replace with "<<replacement text>>", I need to set up a array of
objSelect.Find ? Do you have any ideas?

Regards

-----Original Message-----
From: use-revolution-bounces at lists.runrev.com on behalf of SparkOut
Sent: Sun 2/22/2009 12:44 AM
To: use-revolution at lists.runrev.com
Subject: RE: How to parse one variable to Microsoft Word
 

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.

_______________________________________________
use-revolution mailing list
use-revolution at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list