Find Replace Not Working Within JScript

J

jic

Hi folks.

I have this script,


var w = WScript;
var wa = w.Arguments;
var wo = WScript.StdOut;

var wdFindStop = 0;
var wdFindContinue = 1;
var wdFindAsk = 2;

var wdReplaceNone = 0;
var wdReplaceOne = 2;
var wdReplaceAll = 2;

var fn = "c:\\tmp\\test\\test2.doc";
var word;
try
{
word = GetObject("","Word.Application");
}
catch(e)
{
word = w.CreateObject("Word.Application");
}

//word.Visible = true;

var doc = word.Documents.Open(fn);
var as = word.ActiveDocument;
w.Echo(doc.Name);

var myRange = doc.Range(0,0);

w.Echo("Number of pages: " + myRange.Information(4));
w.Echo(word.ActiveDocument.Name);

////////////////////////////////////////////////////////////////////////
// begin find
////////////////////////////////////////////////////////////////////////
myRange.Find.ClearFormatting();
myRange.Find.Replacement.ClearFormatting();
myRange.Find.Text = "^w^p";
myRange.Find.Replacement.Text = "^p";
myRange.Find.Forward = true;
//myRange.Find.Wrap = wdFindContinue;
myRange.Find.Wrap = wdFindStop; // stop after end of document
myRange.Find.Format = false;
myRange.Find.MatchCase = false;
myRange.Find.MatchWholeWord = false;
myRange.Find.MatchKashida = false;
myRange.Find.MatchDiacritics = false;
myRange.Find.MatchAlefHamza = false;
myRange.Find.MatchControl = false;
myRange.Find.MatchByte = false;
myRange.Find.CorrectHangulEndings = false;
myRange.Find.MatchWildcards = false;
myRange.Find.MatchSoundsLike = false;
myRange.Find.MatchAllWordForms = false;
//myRange.Find.Highlight = false;
myRange.Find.Execute(wdReplaceAll);

doc.Save();
doc.Close();
word.Quit();

which runs ok, but nothing happens to the file. If I run the same
search/replace manually, it works. What I want to do is to delete all
spaces or white characters between a paragraph mark and the last
letter or period. For example, imagine this sentence,

I am going home now.sssssssssssP

the s is replacing one space and the P is standing for the newline (P)
or paragraph mark. So the find/replace should result in,

I am going home now.P

Any idea why this is not working? I am using Word 2003.

thanks,

josé

myRange.Find.MatchWildcards = true;;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top