Hello. I've read may of the threads about finding/replacing text in footers and have found bits and pieces of what I want to do, but can't ut it all together. Would you please help?
I want to find a word in all fotoers of the document (first page footer, Footer, Even Footer, Odd Footer, etc.). I want to replace that word with a word found in the name of the document...
What I'm trying to do is update the document number, which appears on the document name, in the title bar of the document.
The word contains fixed characters, then a number, then a version number, for example, Doc: #12345v1.
So, when we create a new version, now we need to update the footer. First problem I have is that I"m deleting the footer, so all text goes away, including the page number. This is the code I have for clearing up the footer:
Second problem, the code puts the new doc number, but only on the current section, not on all possible footers in the document. If the document has multiple sections and those sections are unlinked, the unlinked sections don't get their footers updated. Here's the code we have for that:
So, what I want to do is to just do a Find/Replace and replace only the doc number.
May I please have some assistance?
I want to find a word in all fotoers of the document (first page footer, Footer, Even Footer, Odd Footer, etc.). I want to replace that word with a word found in the name of the document...
What I'm trying to do is update the document number, which appears on the document name, in the title bar of the document.
The word contains fixed characters, then a number, then a version number, for example, Doc: #12345v1.
So, when we create a new version, now we need to update the footer. First problem I have is that I"m deleting the footer, so all text goes away, including the page number. This is the code I have for clearing up the footer:
Code:
Sub RemoveHeadAndFoot()
Dim oSec As Section
Dim oFoot As HeaderFooter
For Each oSec In ActiveDocument.Sections
For Each oFoot In oSec.Footers
If oFoot.Exists Then oFoot.Range.Delete
Next oFoot
Next oSec
End Sub
Second problem, the code puts the new doc number, but only on the current section, not on all possible footers in the document. If the document has multiple sections and those sections are unlinked, the unlinked sections don't get their footers updated. Here's the code we have for that:
Code:
Private Sub insert_footer(strFooterText As String)
Dim footer_selection As Selection
Dim initial_active_window_view_type As Integer
initial_active_window_view_type = ActiveWindow.View.Type
Application.EnableCancelKey = wdCancelDisabled
If (ActiveWindow.View.SplitSpecial = wdPaneNone) Then
ActiveWindow.ActivePane.View.Type = wdPageView
Else
ActiveWindow.View.Type = wdPageView
End If
ActiveWindow.View.SeekView = wdSeekMainDocument
ActiveDocument.ActiveWindow.View.SeekView = wdSeekCurrentPageFooter
Set footer_selection = ActiveWindow.Selection
' Set the footer text to the sole parameter of this function.
footer_selection.Text = strFooterText
ActiveWindow.View.Type = wdPageView
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range = footer_selection.Range
ActiveWindow.View.Type = wdNormalView
ActiveWindow.View.Type = initial_active_window_view_type
Application.EnableCancelKey = wdCancelInterrupt
End Sub
So, what I want to do is to just do a Find/Replace and replace only the doc number.
May I please have some assistance?