![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Code:
Sub TagtoStyle()
Dim rngStory As Range
For Each rngStory In ActiveDocument.StoryRanges
Application.ScreenUpdating = False
With ActiveDocument.StoryRanges
With rngStory.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "\<[! ]@\>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute
End With
If .Find.Found = False Then
MsgBox "No tags found", vbExclamation
End If
Do While .Find.Found = True
.Style = Split(Split(.Text, "<")(1), ">")(0)
.Text = vbNullString
.Find.Execute
Loop
End With
Next rngStory
Application.ScreenUpdating = True
End Sub
|
|
#2
|
||||
|
||||
|
You have the right idea, but the wrong approach. Try:
Code:
Sub TagtoStyle()
Application.ScreenUpdating = False
Dim rngStory As Range, StrStry As String
For Each rngStory In ActiveDocument.StoryRanges
With rngStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "\<[! ]@\>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute
End With
If .Find.Found = False Then
Select Case rngStory
Case wdCommentsStory: StrStry = "Comments"
Case wdEndnotesStory: StrStry = "Endnotes"
Case wdFootnotesStory: StrStry = "Footnotes"
Case wdMainTextStory: StrStry = "Document Body"
Case Else: StrStry = ""
End Select
If StrStry <> "" Then MsgBox "No tags found in: " & StrStry, vbExclamation
End If
Do While .Find.Found = True
.Style = Split(Split(.Text, "<")(1), ">")(0)
.Text = vbNullString
.Find.Execute
Loop
End With
Next rngStory
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to perform (Find in Main Document) with VBA
|
PassengerBird | Word VBA | 9 | 05-07-2021 01:36 PM |
Removing line break and indentation between footnote number and footnote text in Word
|
jaanross | Word | 5 | 02-06-2020 12:04 AM |
Adding footnote number as part of footnote text
|
NoCalScribe | Word VBA | 3 | 07-15-2019 07:20 PM |
How do I get equal space between main body text and footnote separator line on every page?
|
Different | Word | 1 | 02-09-2015 09:15 PM |
| Macro to find text only footnote numbers | TimFromPhx | Word VBA | 7 | 04-10-2014 07:05 PM |