In my ASPX page I want to find and replace some predefined words. I am
using the following code, but it say objWord.Selection is not there. (
where as this is supported by word )
Set objWord = document.OA1.GetApplication
Set objSelection = objWord.Selection
objSelection.Find.ClearFormatting
objSelection.Find.Replacement.ClearFormatting
objSelection.Find.Text = varFind
objSelection.Find.Replacement.Text = varReplace
objSelection.Find.Forward = True
objSelection.Find.Wrap = wdFindContinue
objSelection.Find.Format = False
objSelection.Find.MatchCase = False
objSelection.Find.MatchWholeWord = False
objSelection.Find.MatchWildcards = False
objSelection.Find.MatchSoundsLike = False
objSelection.Find.MatchAllWordForms = False
objSelection.Find.Execute
Please let me know how can I find and replace word in the client side
word with OA1 activeX.
One Response to “Replace words in Office ActiveX Control”
Leave a Reply
You must be logged in to post a comment.
February 19th, 2009 at 7:22 am
Try the follow vbscript:
Set objWord = document.OA1.GetApplication
objWord.Selection.Find.ClearFormatting
objWord.Selection.Find.Replacement.ClearFormatting
objWord.Selection.Find.Text = varFind
objWord.Selection.Find.Replacement.Text = varReplace
objWord.Selection.Find.Forward = True
objWord.Selection.Find.Wrap = 2
objWord.Selection.Find.Format = False
objWord.Selection.Find.MatchCase = False
objWord.Selection.Find.MatchWholeWord = False
objWord.Selection.Find.MatchWildcards = False
objWord.Selection.Find.MatchSoundsLike = False
objWord.Selection.Find.MatchAllWordForms = False
objWord.Selection.Find.Execute
Or javascript:
//var wdReplaceAll = 2; var wdFindContinue = 1;
var appWord = document.OA1.GetApplication;
appWord.Selection.Find.Execute(‘somevalue’, false, false, false,false, false, 1, false, false, ‘somevalue’, 2, false, false, false, false);
For the javascript, the Find object can’t be get in the component. So it’s necessary to use the vbscript.
Or use the follow method:
helpstring(“Replaces all the specified string value with another string value.”)
HRESULT WordReplace([in] BSTR Text, [in] BSTR ReplaceText, [in] VARIANT_BOOL MatchWholeWord, [in] VARIANT_BOOL MatchCase);
document.OA1.WordReplace “aaa”, “bbb”, true, true