P
progger100
I use the following code to replace all instances of "[VAR]" with "value to
set" in a word document :
Word.Document document;
....
Word.Range rng = document.Content;
rng.Find.ClearFormatting();
Object findText = "[VAR]";
Object matchCase = Type.Missing;
Object matchWholeWord = Type.Missing;
Object matchWildcards = Type.Missing;
Object matchSoundsLike = Type.Missing;
Object matchAllWordForms = Type.Missing;
Object forward = true;
Object wrap = Word.WdFindWrap.wdFindStop;
Object format = Type.Missing;
Object replaceWith = "value to set";
Object replace = Word.WdReplace.wdReplaceAll;
rng.Find.Execute(ref findText, ref matchCase, ref matchWholeWord, ref
matchWildcards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref
wrap, ref format, ref replaceWith, ref replace);
On most pc's, this ALWAYS works fine, but on some pc's, it NEVER works.
The text is not replaced, nothing happens.
I had this problem 2 times until now, while 13 other machines worked
perfectly.
Then I tried :
....
Object replaceWith = Type.Missing;
Object replace = Type.Missing;
while(rng.Find.Execute(ref findText, ref matchCase, ref matchWholeWord, ref
matchWildcards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref
wrap, ref format, ref replaceWith, ref replace) == true)
{
rng.Text = "value to set";// The range is now changed to the found "[VAR]"
instance, we can replace it
rng = document.Content;// reset to loop further
}
This also does or does not work on the same systems.
The basic problem is, that the Find.Execute method does NOT select the found
text part on those pc's where it does not work. Also when I tried to work
through Selection.Find (instead of using Range.Find), nothing changed.
So at this moment, I have before me 2 almost identical pc's, with the same
windows and office version (office XP SP3), handling the same document, and
on 1 pc it works, on the other one it does not. I checked all Word options
and settings, there is no difference.
Does anyone have any idea where this is coming from ?
set" in a word document :
Word.Document document;
....
Word.Range rng = document.Content;
rng.Find.ClearFormatting();
Object findText = "[VAR]";
Object matchCase = Type.Missing;
Object matchWholeWord = Type.Missing;
Object matchWildcards = Type.Missing;
Object matchSoundsLike = Type.Missing;
Object matchAllWordForms = Type.Missing;
Object forward = true;
Object wrap = Word.WdFindWrap.wdFindStop;
Object format = Type.Missing;
Object replaceWith = "value to set";
Object replace = Word.WdReplace.wdReplaceAll;
rng.Find.Execute(ref findText, ref matchCase, ref matchWholeWord, ref
matchWildcards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref
wrap, ref format, ref replaceWith, ref replace);
On most pc's, this ALWAYS works fine, but on some pc's, it NEVER works.
The text is not replaced, nothing happens.
I had this problem 2 times until now, while 13 other machines worked
perfectly.
Then I tried :
....
Object replaceWith = Type.Missing;
Object replace = Type.Missing;
while(rng.Find.Execute(ref findText, ref matchCase, ref matchWholeWord, ref
matchWildcards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref
wrap, ref format, ref replaceWith, ref replace) == true)
{
rng.Text = "value to set";// The range is now changed to the found "[VAR]"
instance, we can replace it
rng = document.Content;// reset to loop further
}
This also does or does not work on the same systems.
The basic problem is, that the Find.Execute method does NOT select the found
text part on those pc's where it does not work. Also when I tried to work
through Selection.Find (instead of using Range.Find), nothing changed.
So at this moment, I have before me 2 almost identical pc's, with the same
windows and office version (office XP SP3), handling the same document, and
on 1 pc it works, on the other one it does not. I checked all Word options
and settings, there is no difference.
Does anyone have any idea where this is coming from ?