Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

VBA code to make a macro that finds italics

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LizW - 23 Nov 2004 18:15 GMT
Hi there,

We didn't have any luck with the Tools, Macro Record feature when trying to
find italics with the find dialog box. The macro won't run.

Is there a way to do it in VBA?

Thanks
Jay Freedman - 23 Nov 2004 19:02 GMT
> Hi there,
>
> We didn't have any luck with the Tools, Macro Record feature when
> trying to find italics with the find dialog box. The macro won't run.
>
> Is there a way to do it in VBA?

Hi Liz,

The braindead recorder is sometimes completely worthless. In this case, it
records the fact that you're looking for formatting, but it forgets to
record what kind of formatting you asked for!

Press Alt+F8 to open the list of macros, select the name you gave to the
recorded macro, and click the Edit button. In the editor, you'll see
something like this:

Sub FindItalic()
'
' FindItalic Macro
' Macro recorded 11/23/2004 by ...
'
  Selection.Find.ClearFormatting
  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
End Sub

After the line  .Text = "" you should insert the missing line:

     .Font.Italic = True

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

LizW - 23 Nov 2004 19:21 GMT
This is how the macro reads now, but the cursor just stays still. What have I
done wrong? Thanks!!!

Sub macro3()
'
' macro3 Macro
' Macro recorded 11/23/2004 by lweiman
'
   Selection.find.ClearFormatting
   With Selection.find
       .Text = .Font.italic = True
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = True
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.find.Execute
   Selection.MoveLeft Unit:=wdCharacter, Count:=1
End Sub

> > Hi there,
> >
[quoted text clipped - 37 lines]
>
>       .Font.Italic = True
LizW - 23 Nov 2004 19:27 GMT
NEVER MIND, PUT IT AFTER LIKE YOU SAID AND IT WORKED!

AWESOME! THANKS!!

> > Hi there,
> >
[quoted text clipped - 37 lines]
>
>       .Font.Italic = True
LizW - 23 Nov 2004 19:35 GMT
Spoke too soon.

It finds one italicized item but when I try to get it to find the next one,
it stays in place. I have to manually move it after to get it to find the
next, with varying results. We need to search for italics throughout the
document and I was hoping to hit Alt I to find the first, mark it, and then
hit Alt I again to find the next instance.

Is there extra code I have to put in for that?

Thanks again.

> > Hi there,
> >
[quoted text clipped - 37 lines]
>
>       .Font.Italic = True
Jay Freedman - 23 Nov 2004 21:58 GMT
Yes, you need more code to do anything more than just going to the text.

The version you showed in one of your posts has the line
  Selection.MoveLeft Unit:=wdCharacter, Count:=1
after the .Execute. That moves the cursor to the left of the italic text. If
you leave the cursor there, the next Find is going to find the same piece
again -- you have to start the next search *after* the end of the first
italic text.

This might be easier to do with a Replace instead of a Find, then you can
just do one Replace All and be done. If you tell me exactly how you "mark"
the text, I can probably come up with a do-it-all macro.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Spoke too soon.
>
[quoted text clipped - 56 lines]
>> Jay Freedman
>> Microsoft Word MVP          FAQ: http://word.mvps.org
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.