Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-21-2020, 07:40 AM
2vbr 2vbr is offline Recording macro for Find Wildcard Windows 10 Recording macro for Find Wildcard Office 2013
Novice
Recording macro for Find Wildcard
 
Join Date: Sep 2020
Posts: 4
2vbr is on a distinguished road
Question Recording macro for Find Wildcard

I have a Word document of labels. Each label looks like this:

Example Label:
Quote:
Name1.
Name2
Name3
To change the font size of all the Name1's on the labels, I used FIND to highlight all text before the period. In other words...



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
Any idea what I'm doing wrong? I recorded a 60sec video of what I did, step by step:

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.
Reply With Quote
  #2  
Old 09-21-2020, 04:05 PM
Guessed's Avatar
Guessed Guessed is offline Recording macro for Find Wildcard Windows 10 Recording macro for Find Wildcard Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,945
Guessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to all
Default

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
Reply With Quote
  #3  
Old 09-21-2020, 05:22 PM
2vbr 2vbr is offline Recording macro for Find Wildcard Windows 10 Recording macro for Find Wildcard Office 2013
Novice
Recording macro for Find Wildcard
 
Join Date: Sep 2020
Posts: 4
2vbr is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 09-21-2020, 05:29 PM
Guessed's Avatar
Guessed Guessed is offline Recording macro for Find Wildcard Windows 10 Recording macro for Find Wildcard Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,945
Guessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to allGuessed is a name known to all
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recording macro for Find Wildcard 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
Recording macro for Find Wildcard Find/Replace Wildcard Needed rsrasc Word VBA 4 11-11-2014 08:28 AM
Recording macro for Find Wildcard Wildcard Find and Replace Ulodesk Word 1 06-23-2014 10:26 AM
Recording macro for Find Wildcard Need help using WildCard Find & Replace Cayce Word 1 06-09-2014 04:17 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 06:29 PM.


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