I'm trying to write some VBA to automate the process of stripping out the first 13 characters of the document name and insert that result as a right-justified footer in all sections of my document. Everything works EXCEPT I can get the for each loop to work for all the other sections of the document. Here is my code. I know it's something to do with the footer properties that I'm missing that casuing it not to work in all sections. Any help would be greatly appreiciated!
oboefajitaman
Sub stripdocumentname()
Dim namelcase As String
Dim sec As Section
namelcase = LCase(Mid(ActiveDocument.Name, 13))
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
For Each sec In ActiveDocument.Sections
ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = False
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Selection.InsertBefore (namelcase)
Selection.Font.Size = 7
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Next sec
End Sub
This demonstrates:
Sub stripdocumentname()
Dim namelcase As String
Dim sec As Section
Dim para As Paragraph
Dim ftr As HeaderFooter
namelcase = LCase(Mid(ActiveDocument.N
For Each sec In ActiveDocument.Sections
For Each ftr In sec.Footers 'Primary, First page and even page
If ftr.Exists Then
Set para = ftr.Range.Paragraphs(1)
para.Alignment = wdAlignParagraphRight
para.Range.InsertBefore namelcase
para.Range.Font.Size = 7
End If
Next ftr
Next sec
End Sub