Reputation: 2230
In Word 2013, using Search and Replace with or without wildcards enabled, I want to replace each occurrence of Hello
at the beginning of a paragraph for Bye
.
The search pattern:
^pHello
only works for non-first line and does not match Hello
at the beginning of the very first paragraph of the document.
How can I match Hello
at the beginning of the document? In Perl this would be done as s/^Hello/Bye/
.
Upvotes: 1
Views: 412
Reputation: 2230
Wildcard to match the beginning of the document seems not to exist.
What I did was to add a paragraph mark at the start of the document, do my searches, then remove the paragraph mark. Here is how it looks like in Perl:
my $word = Win32::OLE->new ('Word.Application', 'Quit') or die $!;
$word->Selection->HomeKey ({Unit => wdStory}); # to the beginning of the doc
$word->Selection->TypeText ({Text => "\n"}); # add the ^p
$word->Selection->HomeKey ({Unit => wdStory}); # to the beginning of the doc
my $search = $document->Content->Find;
$search->{Text} = "^pHello";
$search->Replacement->{Text} = "^pBye";
$search->Execute ();
$word->Selection->Delete; # delete the ^p
Upvotes: 2