Microsoft Office Forums Macro for all docx in subdirectories

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-01-2019, 08:16 PM
createur createur is offline Macro for all docx in subdirectories Windows 10 Macro for all docx in subdirectories Office 2019
Novice
Macro for all docx in subdirectories
 
Join Date: Jun 2019
Posts: 3
createur is on a distinguished road
Default Macro for all docx in subdirectories

Hi. I'm not the best with macros and VBA but I have a macro that I use to style documents that I want to apply to all files spread throughout a series of subdirectories. I've been trying a few things that I've seen suggested here and there but I haven't figured out anything that works. The macro I want to apply is as follows:

Sub QuickFormat()
'
' QuickFormat Macro
' Quick Format for Books
'


Selection.WholeStory
With Selection.ParagraphFormat
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.ActivePane.LargeScroll Down:=3
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^l"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.ActivePane.LargeScroll Down:=3
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = "^p^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.ActivePane.LargeScroll Down:=3
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p "
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
ActiveWindow.ActivePane.LargeScroll Down:=3
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p "
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.WholeStory
With Selection.ParagraphFormat
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.WholeStory
Selection.LanguageID = wdEnglishAUS
Application.CheckLanguage = False
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p^p^p^p"
.Replacement.Text = "^p^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

End Sub

Any help would be greatly appreciated.
Reply With Quote
  #2  
Old 06-01-2019, 08:22 PM
gmayor's Avatar
gmayor gmayor is offline Macro for all docx in subdirectories Windows 10 Macro for all docx in subdirectories Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,026
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

See https://www.gmayor.com/document_batch_processes.htm which will handle the files and folders.
See https://www.gmayor.com/replace_using_wildcards.htm for how to replace extra empty paragraphs.
__________________
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 06-02-2019, 05:49 AM
createur createur is offline Macro for all docx in subdirectories Windows 10 Macro for all docx in subdirectories Office 2019
Novice
Macro for all docx in subdirectories
 
Join Date: Jun 2019
Posts: 3
createur is on a distinguished road
Default

Thanks Graham. That's a great solution for the find/replace things I needed to do. I still need a way to change the language and change the spacing before and after paragraphs though. Any ideas?
Reply With Quote
  #4  
Old 06-02-2019, 07:48 PM
gmayor's Avatar
gmayor gmayor is offline Macro for all docx in subdirectories Windows 10 Macro for all docx in subdirectories Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,026
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

You can create a custom process to do that, using the format described both on the web page and in the program's help files.
__________________
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
  #5  
Old 06-07-2019, 11:05 PM
createur createur is offline Macro for all docx in subdirectories Windows 10 Macro for all docx in subdirectories Office 2019
Novice
Macro for all docx in subdirectories
 
Join Date: Jun 2019
Posts: 3
createur is on a distinguished road
Default

I've spent the last few days trying to figure out how to make this work. Do I have to re-write the whole macro using Boolean or will it work without? To be honest Boolean makes practically zero sense to me. I apologise if that's an extremely ignorant question.
Reply With Quote
  #6  
Old 06-08-2019, 02:45 AM
gmayor's Avatar
gmayor gmayor is offline Macro for all docx in subdirectories Windows 10 Macro for all docx in subdirectories Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,026
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

You have to create the macro as shown on the web site and in the Help file. The Boolean options are there to provide the logging and error reporting. Based on your original macro it would need to be something like

Code:
Function QuickFormat(oDoc As Document) As Boolean
Dim orng As Range
    Set orng = ActiveDocument.Range
    On Error GoTo err_Handler
    With orng.ParagraphFormat
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 0
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
    End With
    orng.LanguageID = wdEnglishAUS
    QuickFormat = True
lbl_Exit:
    Exit Function
err_Handler:
    QuickFormat = False
    Resume lbl_Exit
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
Reply

Tags
docx, subdirectories, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for all docx in subdirectories Run a macro on multiple docx. files Peter Carter Word VBA 23 10-23-2019 10:04 PM
Macro for all docx in subdirectories Run a macro on multiple docx. files terenceyip Word VBA 4 03-20-2019 05:56 PM
How to go through subdirectories in the following macro Kazona Word VBA 0 09-09-2013 06:59 AM
Macro for all docx in subdirectories Getting Macro To Work in .docx file on Website Mhangoy Word 6 09-06-2013 06:57 AM
Help! Can't Get Macro To Work In .docx Opened Off A Website Mhangoy Word VBA 0 08-29-2013 03:02 AM


All times are GMT -7. The time now is 10:41 AM.


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