fessGUID
fessGUID

Reputation:

Replace text in Word Document with ActiveX?

I want replace some string within Word Document using ActiveX and JavaScript, now I have something like this:

var text = Selection.Text;
Selection.Text = text.replace('somesting','somevalue');

But after that I loose all formaing. If I record macros in WinWord I get this:

With Selection.Find
    .Text = "somestring"
    .Replacement.Text = "somevalue"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Find.Execute Replace:=wdReplaceAll

So, how can I rewrite the last string with JS?

Upvotes: 0

Views: 2663

Answers (2)

Manju MS
Manju MS

Reputation: 1

Works well if the text is less than 256 characters. Refer to Article ID: 212543 http://support.microsoft.com/kb/212543 for workaround.

Thanks, Manju

Upvotes: 0

fessGUID
fessGUID

Reputation:

Selection.Find.Execute('somestring',
                       false,
                       false,
                       false,
                       false,
                       false,
                       wdFindContinue,
                       false,
                       false,
                       'somevalue'
                       wdReplaceAll,
                       false,
                       false,
                       false,
                       false);

Also you should have some word constants, like:

var wdReplaceAll = 2;
var wdFindContinue = 1;

Upvotes: 1

Related Questions