#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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 |
#3
|
|||
|
|||
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") |
#4
|
||||
|
||||
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 |
#5
|
|||
|
|||
thatīs great, thanks so much!
|
#6
|
|||
|
|||
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 |
#7
|
|||
|
|||
Quote:
|
#8
|
||||
|
||||
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 |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
Process Automation | saurabhlotankar | Excel Programming | 10 | 06-03-2015 05:50 PM |
Trying to create a macro to batch edit hyperlinks | martinlest | Excel Programming | 5 | 01-09-2015 09:34 AM |
batch file | romanticbiro | Office | 1 | 06-30-2014 06:04 PM |