Link to home
Start Free TrialLog in
Avatar of Andreas Hermle
Andreas HermleFlag for Germany

asked on

Bookmark instances of user defined style

Dear Experts:

Below macro is supposed to bookmark paragraphs a certain way where a user-defined style (user-style) has been applied.

The code does not find any paragraph where the user-defined style (user-style) has been applied. What is wrong with this code?

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Sub BookmarkInstancesOfStyle

Dim strLanguages As Variant
Dim i As Long
Dim frange As Range
 i = 0

Selection.HomeKey wdStory
Selection.Find.Style = ActiveDocument.Styles("user-style")
 
 strLanguages = Array("de", "en", "es", "fr", "it")
 With Selection.Find
 Do While .Execute(FindText:="", Forward:=True, _
 MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
 Set frange = Selection.Range
 ActiveDocument.Bookmarks.Add "MainTOC_" & strLanguages(i), frange
 i = i + 1
 Selection.Collapse wdCollapseEnd
 Loop
 End With
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andreas Hermle

ASKER

Hi Graham,

great, your new code works for me just fine. Thank you so much for your professional help. Have a nice weekend. Regards, Andreas