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 2007

Tip: Looking for answers? Try searching our database.

Find Style: Added Format

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John in Toronto - 30 Nov 2007 17:03 GMT
I am relatively new to VBA.

I want my macro to search for "Heading 2" but each time it runs additional
formatting is added, and the style is not found. I recorded the macro, and
left the default settings:
   Selection.Find.ClearFormatting
   Selection.Find.Style = ActiveDocument.Styles("Heading 2")
   Selection.Find.ParagraphFormat.Borders.Shadow = False
   With Selection.Find
       .Text = ""
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = True
       .MatchCase = False
       .MatchWholeWord = False
       .MatchKashida = False
       .MatchDiacritics = False
       .MatchAlefHamza = False
       .MatchControl = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute

When I look at the find dialog, it shows:
 Style: Heading 2, Border: Top: (Single solid line, Auto, 0.75 pt Line
Width)...

I have tried using different templates too.

Any help would be appreciated.

Thanks

John
Helmut Weber - 30 Nov 2007 20:50 GMT
Hi John,

Sub test66678()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
With rDcm.Find
  .Style = "Heading 2"
  While .Execute
     rDcm.Select ' for testing
     ' what now?
  Wend
End With
End Sub

Depending on what you do to the found range,
you have to define the range "rDcm" anew.

--

Gruß

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
John in Toronto - 30 Nov 2007 21:02 GMT
Many thanks, Helmut.

I can follow what you did, and understand how it works. Is it worth while to
explain why a simple search was not able to do this?

Thanks again,

John

> Hi John,
>
[quoted text clipped - 20 lines]
>
> Vista Small Business, Office XP
Helmut Weber - 30 Nov 2007 21:39 GMT
Hi John,

the macro recorder records everything,
kind of overspecification (!),
a term well known in linguistics.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
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.