Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-22-2017, 09:00 PM
Jude24Joy Jude24Joy is offline Folders within Folders within Folders!!! Windows 8 Folders within Folders within Folders!!! Office 2013
Novice
Folders within Folders within Folders!!!
 
Join Date: Dec 2016
Posts: 15
Jude24Joy is on a distinguished road
Question Folders within Folders within Folders!!!

Hello,

I have previously had marvelous help from here creating some vba code for an ongoing project I'm doing. It runs several jobs on Word documents in whatever folder I select. Sometimes, I have a job to do that has nested folders, and I have to run the vba code on each individual folder. This is a bit annoying, but it's rare enough that it hasn't been bad enough to ask for help.

Now it is! I've had a job come in with 10 plus folders and each one of those folders has 1 or 2 or more sub folders, and each one of those has 4 subfolders! It's taking me forever to select all of those folders. Driving me batty.

Is there a way to automatically run the vba code on all subfolders as well as the main folder I select?

Here's the code I'm using now:

Code:
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
strDocNm = ActiveDocument.FullName
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc")
While strFile <> ""
Application.ScreenUpdating = False
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    With wdDoc
      With .Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = True
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Text = "Test Text 1"
        .Replacement.Text = "Replacement Text 2"
        .Execute Replace:=wdReplaceAll
        .Text = "Test Text 2"
        .Replacement.Text = "Replacement Text 2"
        .Execute Replace:=wdReplaceAll
        .Text = "Test Text 3"
        .Replacement.Text = "Replacement Text 3"
        .Execute Replace:=wdReplaceAll
      End With
      .Fields.Unlink
      .RemoveDocumentInformation (wdRDIAll)
      .Close SaveChanges:=True
    End With
  End If
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
Thanks in advance for any help you can give!
Reply With Quote
  #2  
Old 08-22-2017, 09:53 PM
macropod's Avatar
macropod macropod is offline Folders within Folders within Folders!!! Windows 7 64bit Folders within Folders within Folders!!! Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

See: https://www.msofficeforums.com/word-...html#post47785
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 08-23-2017, 03:46 AM
Jude24Joy Jude24Joy is offline Folders within Folders within Folders!!! Windows 8 Folders within Folders within Folders!!! Office 2013
Novice
Folders within Folders within Folders!!!
 
Join Date: Dec 2016
Posts: 15
Jude24Joy is on a distinguished road
Default

You are awesome!!!

Thank you A BILLION Times!



Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Folders within Folders within Folders!!! Moving Folders iflog Outlook 2 06-17-2014 07:22 AM
How to re-link default email acct folders to default Outlook Data File folders? RDA1959 Outlook 0 03-26-2012 10:55 AM
What happened to these folders djclinton Outlook 2 05-24-2011 09:32 AM
Where did my folders go? WildBill Outlook 0 05-04-2011 08:57 AM
Folders within Folders within Folders!!! Can Access access folders & sub-folders and dig out data? nrg Office 4 06-20-2005 11:09 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:37 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