Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-19-2018, 02:30 PM
prhmusic prhmusic is offline Update fields in all documents in a folder Windows 7 64bit Update fields in all documents in a folder Office 2010 64bit
Novice
Update fields in all documents in a folder
 
Join Date: Jan 2017
Posts: 6
prhmusic is on a distinguished road
Default

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.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to update calculated fields sectionbreak Mail Merge 4 06-04-2014 12:12 AM
Office 2010 Can't Open Or Save Documents in My Documents Folder trippb Office 1 07-12-2013 07:29 AM
Update fields in all documents in a folder macro to update fields PeaceDove Word 3 01-17-2012 02:45 PM
VBA to update certain (but not all) fields sparkyrose Word VBA 0 05-20-2010 12:50 PM
Can no longer update fields! slindsay Word 0 09-03-2009 05:10 PM

Other Forums: Access Forums

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


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