How to parse one variable to Microsoft Word

Nhan, Tran Thi Thanh nhan.tran at rmit.edu.vn
Sat Feb 21 12:00:38 EST 2009



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,

 
-----Original Message-----
From: use-revolution-bounces at lists.runrev.com on behalf of SparkOut
Sent: Sat 2/21/2009 6:22 PM
To: use-revolution at lists.runrev.com
Subject: Re: How to parse one variable to Microsoft Word
 


Nhan, Tran Thi Thanh wrote:
> 
> 
> Hi all,
> 
>  Please help me with this issues: in my Run Rev application, when I click
> on button "Open file" will open file "template.doc" in Microsoft Word. How
> do I parse content of one field of card to this file?
> 
> Regards
> 
> _______________________________________________
> 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
> 
> 
You could put the following VBScript into a custom property of your
application.
Before calling it, you can replace <<replacement text>> and the path to the
document if necessary.
Then do as vbscript. The "result" variable should be returned to Rev, so you
can see if there was any problem with opening the document.

Dim objWord, objDoc, objSelect, wdStory, result

on Error Resume Next
wdStory = 6
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 document>>")
	If Err <> 0 Then
	  result = "Error opening template document"
	End If
  End With
End If

If result = "OK" Then
  Set objSelect = objWord.Selection
  objWord.Selection.HomeKey(wdStory)
  objSelect.Find.Forward = True
  objSelect.Find.Text = "{{replace me}}"
  objSelect.Find.Execute 
  If objSelect.Find.Found Then
    objSelect.Text = "<<replacement text>>"
  End If
  objWord.Selection.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







-- 
View this message in context: http://www.nabble.com/How-to-parse-one-variable-to-Microsoft-Word-tp22133088p22135096.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