Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

find and replace text in header and footers of MS Office doc and excel

by jjap28 (Initiate)
on Oct 11, 2016 at 13:55 UTC ( [id://1173728]=perlquestion: print w/replies, xml ) Need Help??

jjap28 has asked for the wisdom of the Perl Monks concerning the following question:

I was able find/replace text in the body of the Doc file, thanks to internet, but I am not able to find/replace text in the header/footer.



$word = Win32::OLE-> GetActiveObject('Word.Application') || Win32::OLE-> new('Word.Application','Quit'); my $Wordsections = $word->{Sections}; my $sections = $doc->{Sections}; my $n_sections = $sections->{Count}; for my $s ( 1 .. $n_sections ) { my $section = $sections->Item($s); my $headers = $section->{Headers}; my $n_headers = $headers->{Count}; for my $h ( 1 .. $n_headers ) { my $header = $headers->Item($h); print $header->{Range}->{Text}, "\n"; #my $headerRange=$headers->Range("wdHeaderFooterIndex")->InRange +="TRUE"; $Wordsections->Find->ClearFormatting; $Wordsections->Find->{Text} = 'SECRET'; $Wordsections->Find->Replacement->{Text} = "NOFORN"; $Wordsections->Find->Execute({Replace => wdReplaceAll}); } my $footers = $section->{Footers}; my $n_footers = $footers->{Count}; for my $f ( 1 .. $n_footers ) { my $footer = $footers->Item($f); print $footer->{Range}->{Text}, "\n"; } }
  • Comment on find and replace text in header and footers of MS Office doc and excel
  • Download Code

Replies are listed 'Best First'.
Re: find and replace text in header and footers of MS Office doc and excel
by pryrt (Abbot) on Oct 11, 2016 at 14:09 UTC
      I'll give it a shot - thank you

        So these are all Visual basic solutions. I was hoping to see Perl code. I am not familiar with Visual Basic. - Thanks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1173728]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-16 11:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found