#1
|
|||
|
|||
Recording macro for Find Wildcard
I have a Word document of labels. Each label looks like this: Example Label: Quote:
1. use FIND 2. Tick USE WILDCARDS 2. Paste ?*. 3. Find In: Main Document Word highlights all the text before the "." character, and I can manually change the size to what I want. I figured I could make a button macro for this, so I clicked RECORD MACROS, performed all of the above, and then clicked STOP RECORDING. Problem is... when I click the macro button, literally nothing happens. I tried recording the same steps but adding one or two random actions afterwards, like pressing Enter or Space. The Macro recorded the random action, just not the Wildcard Find part. Here's the recorded macro from VBA: Code:
Sub Styles() ' ' Styles Macro ' ' Selection.Find.ClearFormatting With Selection.Find .Text = "?*." .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True End With Selection.Font.Size = 32 Selection.Find.ClearFormatting With Selection.Find .Text = "?*." .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchAllWordForms = False .MatchSoundsLike = False .MatchWildcards = True End With End Sub https://i.imgur.com/6xJn6sk.mp4 Please not that I'm absolutely not a power user. My only knowledge of VBA is clicking the "Record Macro" button. |
#2
|
||||
|
||||
Your macro does lots of settings but there is no .Execute appearing anywhere so I'm not surprised that nothing changes.
You don't need multiple steps if you simply apply a Paragraph Style when you find the character in question. Code:
Sub Macro2() With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Replacement.Style = ActiveDocument.Styles("Heading 1") .Text = "." .Replacement.Text = "." .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll End With End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
I'm afraid that macro didn't work either. All it did was left-Align everything.
https://i.imgur.com/sZOk3nb.mp4 If the lack of an Execute line is the problem, is there a way to add it when Recording macros? Right now I just click the Start Recording button, perform what actions I want, then click Stop Recording. Also, I don't always want Word1 to be Font Size=32. Sometimes I need it to be other sizes. So I was hoping I could use one macro that would change the size of Word1, then I could copy/paste that macro and just go in and change the font size to what's needed. |
#4
|
||||
|
||||
I can't see your videos because I'm on a corporate network that blocks the site. The point of the style change is you configure the target style to whatever look you choose rather than doing local formatting via the macro. Set that style to 32pt size and Centered if that is your preference.
The macro was using the Selection object so the result depends on the selection before you run the macro. You can change it to ActiveDocument.Range if you want to do the entire document. This is the first mention of Word1. What are you actually searching for?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Wildcard to find any one or more words | Maksymromaniuk | Word | 1 | 11-02-2015 01:04 PM |
Need Help With Find and Replace Wildcard | rsrasc | Word VBA | 9 | 10-13-2015 02:37 PM |
Find/Replace Wildcard Needed | rsrasc | Word VBA | 4 | 11-11-2014 08:28 AM |
Wildcard Find and Replace | Ulodesk | Word | 1 | 06-23-2014 10:26 AM |
Need help using WildCard Find & Replace | Cayce | Word | 1 | 06-09-2014 04:17 PM |