-
December 13th, 2011, 07:34 PM
#1
Macro to replace Style of text with certain font
Hello all and thank you for this amazing forum.
I am not a code guru, but please bare with me for a moment cause I really need your help.
I am trying to create a macro for word to help me replace text of certain font and size with certain Style.
Practically, I want to replace text of "Tahoma" "19" to "Heading 1" in... more than 600 documents.
I recorded a macro on word, but it doesn't work. The recorded macro is this:
Code:
Sub WordMacro()
ActiveWindow.DocumentMapPercentWidth = 15
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Heading 1")
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
After searching, reading and trying, I came up with this version:
Code:
Sub MyMacro()
With Selection.Find
.Text = ""
.Font.Name = "Tahoma"
.Font.Size = "19"
.Wrap = wdFindStop
End With
With Selection.Find.Replacement
.Text = ""
.Style = ActiveDocument.Styles("Heading 1")
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Yes, I know it's wrong and you can laugh at it (or me), but I would really appreciate your help if you could please tell me how to correct this. Thank you so much in advance
-
December 13th, 2011, 11:30 PM
#2
Re: Macro to replace Style of text with certain font
I would use VB6 to find the 600 docs first, and then load them one by one.
Macros work with one doc at a time, usually.
AutoRum macro's can be added, as can a custom DOT file, but not sure if it can do what you want.
-
December 14th, 2011, 06:50 AM
#3
Re: Macro to replace Style of text with certain font
Originally Posted by dglienna
I would use VB6 to find the 600 docs first, and then load them one by one.
Macros work with one doc at a time, usually.
AutoRum macro's can be added, as can a custom DOT file, but not sure if it can do what you want.
This is a great idea, thank you very much. I didn't know I can do that...
I'll ask for help... but, in case I won't be able to find someone to help me, can you please help me with the macro, and I can do the documents one by one?
-
December 14th, 2011, 08:12 AM
#4
Re: Macro to replace Style of text with certain font
I did it, and now it works!
My mistake was that since the whole document is in Tahoma, I should focus just on the font size.
Code:
Sub Members()
With Selection.Find
.Text = ""
.Font.Size = "19"
.Wrap = wdFindStop
End With
With Selection.Find.Replacement
.Text = ""
.Style = ActiveDocument.Styles("Heading 1")
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Now I am writing an applescript to run this macro on all documents in a folder.
Wish me luck guys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|