Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-18-2019, 02:44 AM
dita dita is offline Macro for batch process Windows XP Macro for batch process Office 2010 64bit
Advanced Beginner
Macro for batch process
 
Join Date: Apr 2018
Posts: 34
dita is on a distinguished road
Default Macro for batch process

Hello everyone,


I have created a macro to change the font properties in a document but would like to run the same macro in all DOC files placed in a specific folder.


Is there any code to do that in a batch process?


If yes, which code should I use for that and where/how to include it in the macro below?


Note that Macro should work for .DOC formats although I also will be use it for .DOCX.


Many thanks!


Sub Macro1()
With ActiveDocument.Styles("Normal").Font


.NameFarEast = "Calibri"
End With
With ActiveDocument.Styles("Normal")
.AutomaticallyUpdate = False
.BaseStyle = ""
.NextParagraphStyle = "Normal"
End With
End Sub
Reply With Quote
  #2  
Old 10-18-2019, 04:10 AM
gmayor's Avatar
gmayor gmayor is offline Macro for batch process Windows 10 Macro for batch process Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 following will work. It needs a small change to your macro

Code:
Sub BatchProcess()
Dim strFile As String
Dim strPath As String
Dim oDoc As Document
Dim fDialog As FileDialog
    Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
    With fDialog
        .TITLE = "Select folder and click OK"
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then
            MsgBox "Cancelled By User", , "List Folder Contents"
            Exit Sub
        End If
        strPath = fDialog.SelectedItems.Item(1)
        Do Until Right(strPath, 1) = "\"
            strPath = strPath + "\"
        Loop
    End With
    strFile = Dir$(strPath & "*.doc")
    While strFile <> ""
        Set oDoc = Documents.Open(strPath & strFile)
        Macro1 oDoc
        oDoc.Close SaveChanges:=wdSaveChanges
        strFile = Dir$()
    Wend
lbl_Exit:
    Exit Sub
End Sub

Private Sub Macro1(oDoc As Document)
    With oDoc.Styles("Normal").Font
        .NameFarEast = "Calibri"
    End With
    With oDoc.Styles("Normal")
        .AutomaticallyUpdate = False
        .BaseStyle = ""
        .NextParagraphStyle = "Normal"
    End With
End Sub
__________________
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 10-18-2019, 06:01 AM
dita dita is offline Macro for batch process Windows XP Macro for batch process Office 2010 64bit
Advanced Beginner
Macro for batch process
 
Join Date: Apr 2018
Posts: 34
dita is on a distinguished road
Default

It works. Thanks so much!!!


Can I use the same macro for DOCX files by simply changing the code from .doc to .docx?




strFile = Dir$(strPath & "*.docx")
Reply With Quote
  #4  
Old 10-18-2019, 07:50 AM
gmayor's Avatar
gmayor gmayor is offline Macro for batch process Windows 10 Macro for batch process Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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

You don't need to change anything.
__________________
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 10-21-2019, 02:45 AM
dita dita is offline Macro for batch process Windows XP Macro for batch process Office 2010 64bit
Advanced Beginner
Macro for batch process
 
Join Date: Apr 2018
Posts: 34
dita is on a distinguished road
Default

thatīs great, thanks so much!
Reply With Quote
  #6  
Old 10-23-2019, 12:26 AM
Leslie Leslie is offline Macro for batch process Windows 8 Macro for batch process Office 2010
Novice
 
Join Date: Oct 2019
Posts: 13
Leslie is on a distinguished road
Default

Statement by statement with manual intervention, how to run macros with keyboard control operation..

For instance: there may be 10 paragraphs. Particular statements of few paragraphs need macros run by keyboard control operation. Like Ctrl+5, for instance, so that operation gets completed for the selected line.

Note: my first post
Reply With Quote
  #7  
Old 10-27-2019, 09:26 AM
Leslie Leslie is offline Macro for batch process Windows 8 Macro for batch process Office 2010
Novice
 
Join Date: Oct 2019
Posts: 13
Leslie is on a distinguished road
Default

Quote:
Originally Posted by Leslie View Post
Statement by statement with manual intervention, how to run macros with keyboard control operation..

For instance: there may be 10 paragraphs. Particular statements of few paragraphs need macros run by keyboard control operation. Like Ctrl+5, for instance, so that operation gets completed for the selected line.

Note: my first post
Replies appreciated.
Reply With Quote
  #8  
Old 10-27-2019, 09:15 PM
gmayor's Avatar
gmayor gmayor is offline Macro for batch process Windows 10 Macro for batch process Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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

You probably got no replies because no-one knows what it is that you are trying to do now. You asked for a batch process to perform your code function on various documents. I provided that. What EXACTLY do you want now? Your message makes no sense at all.
__________________
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

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for batch process Batch applying a macro to remove Header and Footer using Batch Auto Addin Edszx Word VBA 2 05-27-2019 11:16 PM
Batch re-naming twols26 Word VBA 7 06-16-2015 12:29 PM
Macro for batch process Process Automation saurabhlotankar Excel Programming 10 06-03-2015 05:50 PM
Macro for batch process Trying to create a macro to batch edit hyperlinks martinlest Excel Programming 5 01-09-2015 09:34 AM
Macro for batch process batch file romanticbiro Office 1 06-30-2014 06:04 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:44 AM.


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