PDA

View Full Version : [SOLVED:] Macro to change the font of page number to New Rocker in Word 2007



staicumihai
12-27-2017, 05:25 AM
Hi guys.

I have 200 word documents and I want to change the font of the page number (in the footer) to New Rocker font so that it matches the text on the page.

Can I do that using a macro ?

Thanks!

macropod
12-27-2017, 05:02 PM
For that you could use a macro like:

Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
Dim Sctn As Section, HdFt As HeaderFooter
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
If strFolder & "\" & strFile <> strDocNm Then
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
For Each Sctn In .Sections
If Sctn.Index = 1 Then
For Each HdFt In Sctn.Footers
If HdFt.Exists = True Then Call FooterUpdate(HdFt)
Next
Else
For Each HdFt In Sctn.Footers
If HdFt.Exists = True Then
If HdFt.LinkToPrevious = False Then Call FooterUpdate(HdFt)
End If
Next
End If
Next
.Close SaveChanges:=True
End With
End If
strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub


Sub FooterUpdate(HdFt As HeaderFooter)
Dim Fld As Field
For Each Fld In HdFt.Range.Fields
With Fld
If .Type = wdFieldPage Then
With .Code
If InStr(UCase(.Text), "CHARFORMAT") = 0 Then
.Text = .Text & "\* Charformat"
End If
.Font.Name = "New Rocker"
End With
Exit For
End If
End With
Next
End Sub


Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function

staicumihai
12-28-2017, 01:06 AM
Thats just great man

Thank you so much.

Have a Happy New Year!