For more information, see StoryRanges, NextStoryRange, WdStoryType, and Range.
Replace text in Word textbox objects using VSTO and C #
01
/// <summary>
02
/// Search for and replace the text
03
/// </summary>
04
/// <param name="wordApp"></param>
05
/// <param name="oldStr"></param>
06
/// <param name="newStr"></param>
07
public
void
SearchReplace(
string
oldStr,
string
newStr)
08
{
09
# Region text area
10
object
replaceAll = WdReplace.wdReplaceAll;
11
12
wordApp.Selection.Find.ClearFormatting();
13
wordApp.Selection.Find.Text = oldStr;
14
15
wordApp.Selection.Find.Replacement.ClearFormatting();
16
wordApp.Selection.Find.Replacement.Text = newStr;
17
18
wordApp.Selection.Find.Execute(
19
ref
missing,
ref
missing,
ref
missing,
ref
missing,
ref
missing,
20
ref
missing,
ref
missing,
ref
missing,
ref
missing,
ref
missing,
21
ref
replaceAll,
ref
missing,
ref
missing,
ref
missing,
ref
missing);
22
#endregion
23
24
# Region text box
25
StoryRanges sr = wordDoc.StoryRanges;
26