Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-18-2015, 08:39 AM
MBragg
Guest
 
Posts: n/a
Default Update Multiple Documents Footer

I have written a Macro to update text in multiple DOCX files, however it will not update the Footer. I have templates to evaluations, and I need to make a Rev change to all of them at once. Can anyone update the following Macro to Search and replace text in the Footer?:

Sub Update_DOCX_File_Sigs()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, DOCXDoc
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.DOCX", vbNormal)
While strFile <> ""
Set DOCXDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With DOCXDoc.Range.Find
.ClearFormatting
.Text = "72-0006-3500/8"
.Replacement.Text = "72-0006-3500/9"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll


End With
DOCXDoc.Close SaveChanges:=True
strFile = Dir()
Wend
Set DOCXDoc = Nothing
Application.ScreenUpdating = True
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
Attached Files
File Type: txt Macro.txt (1.1 KB, 10 views)
Reply With Quote
  #2  
Old 08-19-2015, 01:47 AM
gmayor's Avatar
gmayor gmayor is offline Update Multiple Documents Footer Windows 7 64bit Update Multiple Documents Footer Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The reason it doesn't update the footer is that your macro doesn't address the footer. It addresses only the main storyrange i.e. DOCXDoc.Range. If you want to address all the ranges in a document, or specific ranges, you need to loop through all the storyranges or address the specific range. The following takes the former approach. You might also be interested in http://www.gmayor.com/document_batch_processes.htm which has built-in processes to handle this including the sub foilders of the selected folder if required.

Code:
Option Explicit

Sub Update_DOCX_File_Sigs()
    Application.ScreenUpdating = False
    Dim strFolder As String, strFile As String, DOCXDoc
    Dim oStory As Range
    strFolder = GetFolder
    If strFolder = "" Then Exit Sub
    strFile = Dir(strFolder & "\*.DOCX", vbNormal)
    While strFile <> ""
        Set DOCXDoc = Documents.Open(Filename:=strFolder & "\" & strFile, _
                                     AddToRecentFiles:=False, _
                                     Visible:=False)
        For Each oStory In DOCXDoc.StoryRanges
            ReplaceInRange oStory
            If oStory.StoryType <> wdMainTextStory Then
                While Not (oStory.NextStoryRange Is Nothing)
                    Set oStory = oStory.NextStoryRange
                    ReplaceInRange oStory
                Wend
            End If
        Next oStory
        DOCXDoc.Close SaveChanges:=True
        strFile = Dir()
    Wend
    Set oStory = Nothing
    Set DOCXDoc = Nothing
    Application.ScreenUpdating = True
End Sub

Private Sub ReplaceInRange(oRng As Range)
    With oRng.Find
        .ClearFormatting
        .Text = "72-0006-3500/8"
        .Replacement.Text = "72-0006-3500/9"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
    End With
End Sub

Private 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
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 08-19-2015, 10:45 AM
MBragg
Guest
 
Posts: n/a
Default

Worked Perfectly, thanks a heap
Reply With Quote
Reply

Tags
footer, update templates



Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Multiple Documents Footer Replace footer image in multiple Word documents heyjim Drawing and Graphics 1 08-07-2015 05:23 PM
help needed for automatic update of footer sanju71821 Word 7 07-01-2015 08:18 AM
Update Multiple Documents Footer update template in all documents vangxbg Word VBA 1 02-25-2013 04:04 AM
Auto update footer in Word 2007 worduser1970 Word 4 11-27-2012 08:02 AM
header/footer problems only in certain documents Endzone Word 5 08-15-2012 01:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:08 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft