Let me set the stage a bit more.
I have a directory "S:\disaster Recovery Planning" which has multiple sub-folders with multiple Word documents in each. For example:
|
S:\disaster Recovery Planning\Standards.docx
S:\disaster Recovery Planning\System1\System1.docx
S:\disaster Recovery Planning\System2\System2.docx
|
Each of these Word documents has a field that is hooked to a heading in the S:\disaster Recovery Planning\Standards.docx file by a bookmark. For example, the bookmark for the "Overview" headings is this:
|
{ INCLUDETEXT "S:\\Disaster Recovery Planning\ \DRMStandards.docx" Overview_01 }
|
In the DRMStandards.docx file, I have this as the "Overview_01" bookmark:
|
{ TITLE \* MERGEFORMAT } - Section 01 - Overview
|
What I want to be able to do is to go to the DRMStandards.docx file and change the text in the Overview_01 bookmark - say I want to make it be the following (as a simple example):
|
{ TITLE \* MERGEFORMAT } - Part 01 - Overview
|
I want to run the macro to go to each document and run the RefreshAllFields code so that I don't have to manually open up S:\disaster Recovery Planning\System1\System1.docx, run the RefreshAllFields macro, close the file, open S:\disaster Recovery Planning\System2\System2.docx, run the RefreshAllFields macro, and so forth.
I set this up, with the bookmarks and fields because I want the flexibility to edit the heading verbiage and be able to update all the Word documents that are set up like this. I need to scale this methodology because eventually, there could be hundreds of Word documents in this folder structure and manually opening each is not going to be an option! <grin>
Thus, that's why I posted my initial reply.
I created a new .DOTM file and created the UpdateDocuments macro as follows:
Code:
Sub UpdateDocuments()
'
' UpdateDocuments Macro
'
Application.ScreenUpdating = False
Dim strDocNm As String, strFolder As String, strFile As String, wdDoc As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
strDocNm = ThisDocument.FullName
While strFile <> ""
If strFolder & "\" & strFile <> strDocNm Then
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With wdDoc
.Fields.Update
.PrintPreview
.ClosePrintPreview
.Close SaveChanges:=True
End With
End If
strFile = Dir()
Wend
Set wdDoc = 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
When I ran that code, I chose the "S:\Disaster Recovery Planning\AEROSCOUT" folder which has 3 Word documents" with these Modified Dates:
|
File 1 has a modified date = 1/5/2018 10:22 AM
File 2 has a modified date = 1/5/2018 10:25 AM
File 3 has a modified date = 1/5/2018 10:26 AM
|
After I ran the code, I expected the "Date Modified" column to change, but it didn't - I still see
|
File 1 has a modified date = 1/5/2018 10:22 AM
File 2 has a modified date = 1/5/2018 10:25 AM
File 3 has a modified date = 1/5/2018 10:26 AM
|
I'm sorry if I just changed the requirements on you - I didn't mean to in light of seeing your comment on post #15 -
https://www.msofficeforums.com/word-...html#post47785 - as I was trying to do this on my own. I didn't post my question until after I had hit a brick wall.
I hope that gives more insight into what I'm trying to do.