Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
hi!
I have around 200 files which header and footer need to be change from times new roman to arial. can anyone help me with this using macro? thanks in advance. |
#2
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
Assuming the documents are not protected forms and are not password
protected then the following should work Sub BatchChangeHeaderFooter() On Error GoTo err_FolderContents Dim oSection As Section Dim oHeader As HeaderFooter Dim oFooter As HeaderFooter Dim DocList As String Dim DocDir As String Dim fDialog As FileDialog Set fDialog = Application.FileDialog(msoFileDialogFolderPicker) With fDialog .Title = "Select Folder containing the documents to be edited and click OK" .AllowMultiSelect = False .InitialView = msoFileDialogViewList If .Show -1 Then MsgBox "Cancelled By User" Exit Sub End If PathToUse = fDialog.SelectedItems.Item(1) If Right(PathToUse, 1) "\" Then PathToUse = PathToUse + "\" End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If Application.ScreenUpdating = False DocList = Dir$(DocDir & "*.doc") Do While DocList "" Documents.Open DocList For Each oSection In ActiveDocument.Sections For Each oHeader In oSection.Headers If oHeader.Exists Then oHeader.Range.Font.name = "Arial" End If Next oHeader For Each oFooter In oSection.Footers If oFooter.Exists Then oFooter.Range.Font.name = "Arial" End If Next oFooter Next oSection ActiveDocument.Close SaveChanges:=wdSaveChanges DocList = Dir$() Loop Application.ScreenUpdating = True Exit Sub err_FolderContents: MsgBox Err.Description Exit Sub End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Brie wrote: hi! I have around 200 files which header and footer need to be change from times new roman to arial. can anyone help me with this using macro? thanks in advance. |
#3
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
Thanks a lot Graham!
It works great! Brie "Graham Mayor" wrote: Assuming the documents are not protected forms and are not password protected then the following should work Sub BatchChangeHeaderFooter() On Error GoTo err_FolderContents Dim oSection As Section Dim oHeader As HeaderFooter Dim oFooter As HeaderFooter Dim DocList As String Dim DocDir As String Dim fDialog As FileDialog Set fDialog = Application.FileDialog(msoFileDialogFolderPicker) With fDialog .Title = "Select Folder containing the documents to be edited and click OK" .AllowMultiSelect = False .InitialView = msoFileDialogViewList If .Show -1 Then MsgBox "Cancelled By User" Exit Sub End If PathToUse = fDialog.SelectedItems.Item(1) If Right(PathToUse, 1) "\" Then PathToUse = PathToUse + "\" End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If Application.ScreenUpdating = False DocList = Dir$(DocDir & "*.doc") Do While DocList "" Documents.Open DocList For Each oSection In ActiveDocument.Sections For Each oHeader In oSection.Headers If oHeader.Exists Then oHeader.Range.Font.name = "Arial" End If Next oHeader For Each oFooter In oSection.Footers If oFooter.Exists Then oFooter.Range.Font.name = "Arial" End If Next oFooter Next oSection ActiveDocument.Close SaveChanges:=wdSaveChanges DocList = Dir$() Loop Application.ScreenUpdating = True Exit Sub err_FolderContents: MsgBox Err.Description Exit Sub End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Brie wrote: hi! I have around 200 files which header and footer need to be change from times new roman to arial. can anyone help me with this using macro? thanks in advance. |
#4
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
You are welcome
![]() -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Brie wrote: Thanks a lot Graham! It works great! Brie "Graham Mayor" wrote: Assuming the documents are not protected forms and are not password protected then the following should work Sub BatchChangeHeaderFooter() On Error GoTo err_FolderContents Dim oSection As Section Dim oHeader As HeaderFooter Dim oFooter As HeaderFooter Dim DocList As String Dim DocDir As String Dim fDialog As FileDialog Set fDialog = Application.FileDialog(msoFileDialogFolderPicker) With fDialog .Title = "Select Folder containing the documents to be edited and click OK" .AllowMultiSelect = False .InitialView = msoFileDialogViewList If .Show -1 Then MsgBox "Cancelled By User" Exit Sub End If PathToUse = fDialog.SelectedItems.Item(1) If Right(PathToUse, 1) "\" Then PathToUse = PathToUse + "\" End With If Documents.Count 0 Then Documents.Close SaveChanges:=wdPromptToSaveChanges End If Application.ScreenUpdating = False DocList = Dir$(DocDir & "*.doc") Do While DocList "" Documents.Open DocList For Each oSection In ActiveDocument.Sections For Each oHeader In oSection.Headers If oHeader.Exists Then oHeader.Range.Font.name = "Arial" End If Next oHeader For Each oFooter In oSection.Footers If oFooter.Exists Then oFooter.Range.Font.name = "Arial" End If Next oFooter Next oSection ActiveDocument.Close SaveChanges:=wdSaveChanges DocList = Dir$() Loop Application.ScreenUpdating = True Exit Sub err_FolderContents: MsgBox Err.Description Exit Sub End Sub -- Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org Brie wrote: hi! I have around 200 files which header and footer need to be change from times new roman to arial. can anyone help me with this using macro? thanks in advance. |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I change the actual header and footer margins? | Page Layout | |||
Can't change first header/footer in section to first page header | Page Layout | |||
Header/footer font color | Microsoft Word Help | |||
How do I change the footer & header to the same text in multiple . | Page Layout | |||
How do I change tabs in the header/footer of only one section ? | Page Layout |