PDA

View Full Version : Solved: Delete text in specific section's footer?



clhare
07-22-2005, 03:01 AM
Is it possible to use a macro in Word that will go into the footer of a specific section and delete lines 2-4 of text in the first page footer only of that section?
I need to be able to do this in sections 4 and 6 of my document and can't figure out how.

Cheryl

fumei
07-22-2005, 09:54 AM
Yes.

Say the footer in Section 4 First page is:

Line 1
Line 2
Line 3
Line 4

Sub Section4Footer()
Dim oRange As Word.Range
Set oRange = _
ActiveDocument.Sections(4).Footers(wdHeaderFooterFirstPage).Range
oRange.Text = "New Line A" & vbCrLf & _
"New line B" & vbCrLf & _
"New line C" & vbCrLf & _
"New line D"
Set oRange = Nothing
End Sub

will change it to Line A, Line B..... It does not affect any other footer.

clhare
07-25-2005, 04:09 AM
What if I can't tell the macro the exact text in lines 2-4? I just know I want to delete whatever text in on those lines of that particular footer.

Cheryl

MOS MASTER
07-25-2005, 11:15 AM
What if I can't tell the macro the exact text in lines 2-4? I just know I want to delete whatever text in on those lines of that particular footer.

Cheryl

Hi Cheryl, :yes

Something like:
Sub Section4Footer()
Dim oRange As Word.Range

Set oRange = _
ActiveDocument.Sections(4).Footers(wdHeaderFooterFirstPage).Range

With oRange
.Paragraphs(4).Range.Delete
.Paragraphs(3).Range.Delete
.Paragraphs(2).Range.Delete
End With

Set oRange = Nothing
End Sub


Remember delete backwards (look at the numbering in my example) you are changing a collection over here!

HTH, :whistle:

fumei
07-25-2005, 06:38 PM
Please clarify and be specific in your requests.

Do you want to delete the TEXT of each line, but KEEP the lines (ie. keep the paragraph marks)?

Or do you want to delete everything?

It is hard to tell from your post. Please note that Joost's code removes the paragraph. Actually, you should be able to figure this out from the original code.

If you want to delete everything out of a specific footer:
Dim oRange As Word.Range
Set oRange = _
ActiveDocument.Sections(4).Footers(wdHeaderFooterFirstPage).Range
oRange.Delete
Set oRange = Nothing

OR;

oRange.Text = ""

Please specify exactly what you want.

fumei
07-25-2005, 09:49 PM
Here is an alternative. It makes a range of the footer (First Page Section 4), moves the start until it finds a paragraph mark, moves one more character - to the start of the next line - then deletes the range. In other words, it deletes everything but the first paragraph.
Dim oRange As Word.Range
Set oRange = ActiveDocument.Sections(4). _
Footers(wdHeaderFooterFirstPage).Range
With oRange
.MoveStartUntil cset:=Chr(13)
.MoveEnd unit:=wdCharacter, Count:=1
.Delete
End With
Set oRange = Nothing

fumei
07-25-2005, 09:55 PM
Oh, and Joost...why declare oPara if you never use it?

MOS MASTER
07-26-2005, 09:34 AM
Oh, and Joost...why declare oPara if you never use it?

No reason forgot to delete it! :yes

MOS MASTER
07-26-2005, 09:37 AM
Please clarify and be specific in your requests.

Do you want to delete the TEXT of each line, but KEEP the lines (ie. keep the paragraph marks)?


Yes its a good idea to understand what Cheryl means with a "line". :yes (But I'm sure there's stuff enough to be clear to a sollution) :whistle:

clhare
07-27-2005, 07:06 AM
Joost's solution was exactly what I needed. I needed to delete the entire paragraph, not just the text.

Thanks so much for your help!

fumei
07-27-2005, 07:31 AM
Sniff. Joost, Joost Joost...it's all about Joost. I think my code is better.

.....you better think that is funny Joost...it is meant to be!

MOS MASTER
07-27-2005, 09:36 AM
Joost's solution was exactly what I needed. I needed to delete the entire paragraph, not just the text.

Thanks so much for your help!

Hi Cheryl, :yes

Glad your problems solved...you're welcome! (Ps don't forget my sollution was based on Gerry's code!)

Later...:whistle:

MOS MASTER
07-27-2005, 09:38 AM
Sniff. Joost, Joost Joost...it's all about Joost. I think my code is better.

.....you better think that is funny Joost...it is meant to be!

Sure no problem! :yes
I have the same fealing Gerry, Gerry, Gerry...it's always GERRY! :jawdown: :rofl: