alcani
asked on
Delete odd & even headers in MS Word
Hi,
I'm looking for a simple VBA code in order to create a macro that will examine all header and footers (odd & even) of a MS Word document and delete the content.
Thank you.
Regards,
I'm looking for a simple VBA code in order to create a macro that will examine all header and footers (odd & even) of a MS Word document and delete the content.
Thank you.
Regards,
ASKER
Ok thank you, this works ok.
If I would like to add juste after remove the text other information in a odd header /footer, which will will the syntax?
If I would like to add juste after remove the text other information in a odd header /footer, which will will the syntax?
This addresses each footer type separately. The headers work in the same way.
Sub EachFooterTypeToBlank(Doc As Word.Document)
Dim sec As Word.Section
Dim ftr As Word.HeaderFooter
Dim hdr As Word.HeaderFooter
For Each sec In Doc.Sections
Set ftr = sec.Footers(wdHeaderFooterPrimary)
ftr.Range.Text = ""
Set ftr = sec.Footers(wdHeaderFooterFirstPage)
ftr.Range.Text = ""
Set ftr = sec.Footers(wdHeaderFooterEvenPages)
ftr.Range.Text = ""
Next sec
End Sub
ASKER
Thanks. I'm sorry ... I'm learning...
I copied your code and pasted it in my VBA editor.
However I'm not able to see the macro "EachFooterTypeToBlank".
I saw that the variable "Doc As Word.Document" is doing something because I'm not able to see the macro when I try to execute it.
I tried like this:
Sub EachFooterTypeToBlank()
Dim Doc As Word.Document
........
Then I could execute it but it send me an error.
I'm using Word 2003.
What is the reason?
I copied your code and pasted it in my VBA editor.
However I'm not able to see the macro "EachFooterTypeToBlank".
I saw that the variable "Doc As Word.Document" is doing something because I'm not able to see the macro when I try to execute it.
I tried like this:
Sub EachFooterTypeToBlank()
Dim Doc As Word.Document
........
Then I could execute it but it send me an error.
I'm using Word 2003.
What is the reason?
You have to tell the macro which document the Doc variable represents.
Try:
Try:
Sub EachFooterTypeToBlank()
Dim Doc As Word.Document
Dim sec As Word.Section
Dim ftr As Word.HeaderFooter
Dim hdr As Word.HeaderFooter
Set Doc = ActiveDocument '<----- New line
For Each sec In Doc.Sections
Set ftr = sec.Footers(wdHeaderFooterPrimary)
ftr.Range.Text = ""
Set ftr = sec.Footers(wdHeaderFooterFirstPage)
ftr.Range.Text = ""
Set ftr = sec.Footers(wdHeaderFooterEvenPages)
ftr.Range.Text = ""
Next sec
End Sub
ASKER
Thank you. I really appreciate your help.
Is it posible to insert a header/footer with several lines eg.
Something like that
For Each sec In Doc.Sections
Set ftr = sec.Footers(wdHeaderFooter Primary)
ftr.Range.Text = "LINE 1"
ftr.Range.Text = "LINE 2"
etc.....
In the same header?
Is it posible to insert a header/footer with several lines eg.
Something like that
For Each sec In Doc.Sections
Set ftr = sec.Footers(wdHeaderFooter
ftr.Range.Text = "LINE 1"
ftr.Range.Text = "LINE 2"
etc.....
In the same header?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!!!
Open in new window