J
JB
Hi Folks,
I've written some code to check the character style in paragraphs and
'do stuff' based of the style found. First question: Is it better to
use the 'Do While' clause with this (which I'm thinking it might be).
Second Question: Is it better to use range instead of selection, and if
so how do I convert this to ranges? I've never used ranges before and
don't really know that much about the properties/methods.
Any pointers/improvements gratefully accepted.
Cheers
J
Dim x As Integer, y As Integer, s As Integer
Dim StyleNow As String
Dim test As Variant, test1 As Variant
StyleNow = "Persname"
SavedMemData = ActiveDocument.BuiltInDocumentProperties(wdPropertyParas)
For x = 0 To SavedMemData - 1
styletype = Selection.Style
For s = 1 To 6
y = 0
test1 = Selection.Paragraphs.Last
test = Selection.Document.Paragraphs.Item(x + 1)
If test <> test1 Then GoTo End1
If Selection.Style = StyleNow Then
StyleNow = Selection.Style
Selection.MoveLeft wdCharacter, 1
Selection.MoveRight Unit:=wdWord, Count:=1, _
Extend:=wdExtend
If StyleNow = "Persname" Then GoTo Pers1
While StyleNow = "Persname"
Selection.MoveRight wdWord, 1, wdExtend
If Right(Selection.Style, 5) = "Entry" Then
Selection.MoveLeft wdWord, 1, wdExtend
Selection.MoveLeft wdCharacter, 1, wdExtend
StyleNow = Selection.Style
GoTo CheckEntry
End If
Wend
This must be performed on multiple paragraphs and multiple styles to
have the effect I need.
I've written some code to check the character style in paragraphs and
'do stuff' based of the style found. First question: Is it better to
use the 'Do While' clause with this (which I'm thinking it might be).
Second Question: Is it better to use range instead of selection, and if
so how do I convert this to ranges? I've never used ranges before and
don't really know that much about the properties/methods.
Any pointers/improvements gratefully accepted.
Cheers
J
Dim x As Integer, y As Integer, s As Integer
Dim StyleNow As String
Dim test As Variant, test1 As Variant
StyleNow = "Persname"
SavedMemData = ActiveDocument.BuiltInDocumentProperties(wdPropertyParas)
For x = 0 To SavedMemData - 1
styletype = Selection.Style
For s = 1 To 6
y = 0
test1 = Selection.Paragraphs.Last
test = Selection.Document.Paragraphs.Item(x + 1)
If test <> test1 Then GoTo End1
If Selection.Style = StyleNow Then
StyleNow = Selection.Style
Selection.MoveLeft wdCharacter, 1
Selection.MoveRight Unit:=wdWord, Count:=1, _
Extend:=wdExtend
If StyleNow = "Persname" Then GoTo Pers1
While StyleNow = "Persname"
Selection.MoveRight wdWord, 1, wdExtend
If Right(Selection.Style, 5) = "Entry" Then
Selection.MoveLeft wdWord, 1, wdExtend
Selection.MoveLeft wdCharacter, 1, wdExtend
StyleNow = Selection.Style
GoTo CheckEntry
End If
Wend
This must be performed on multiple paragraphs and multiple styles to
have the effect I need.