J
John
Hi Folks,
I'm having a problem with Word XP and selecting text from a VBA macro! the
code I've been using is listed below and if anyone can have a look and
suggest a better way of doing this (and possibly one which works for XP) I
would be very grateful. This works fine in office 2k but XP is kicking me
up and down the house!
Cheers
John
p.s. I'm new to VBA and this isn't my code so I'm still a bit sketchy on how
all the selection thing works. Any pointers gratefuly accepted.
Public Sub AmendList()
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
Persname:
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.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
y = y + 1
If y = 20 Then GoTo endnow
If test <> test1 Then
If Right(Selection.Style, 5) = "Entry" Then
ListType(x) = Selection.Style
End If
End If
GoTo Persname
Else
End1:
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1,
Extend:=wdExtend
If StyleNow = "Persinits" Then
txtInits(x) = Selection.Text
ElseIf StyleNow = "Perstitle" Then
txtTitles(x) = Selection.Text
ElseIf StyleNow = "Persname" Then
txtpersname(x) = Selection.Text
ElseIf StyleNow = "Office" Then
txtOffices(x) = Selection.Text
ElseIf StyleNow = "Department" Then
txtDepartments(x) = Selection.Text
ElseIf StyleNow = "Email" Then
txtEmails(x) = Selection.Text
End If
Selection.MoveRight Unit:=wdCharacter, Count:=2
StyleNow = Selection.Style
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=1,
Extend:=wdExtend
If Right(Selection.Style, 5) = "Entry" Then
ListType(x) = Selection.Style
End If
Selection.MoveRight Unit:=wdCharacter, Count:=2
End If
If test <> test1 Then s = 6
Next s
Next x
endnow:
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If StyleNow = "Persinits" Then
txtInits(x) = Selection.Text
ElseIf StyleNow = "Perstitle" Then
txtTitles(x) = Selection.Text
ElseIf StyleNow = "Persname" Then
txtpersname(x) = Selection.Text
ElseIf StyleNow = "Office" Then
txtOffices(x) = Selection.Text
ElseIf StyleNow = "Department" Then
txtDepartments(x) = Selection.Text
ElseIf StyleNow = "Email" Then
txtEmails(x) = Selection.Text
End If
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Right(Selection.Style, 5) = "Entry" Then
ListType(x) = Selection.Style
End If
Selection.MoveRight Unit:=wdCharacter, Count:=2
End Sub
I'm having a problem with Word XP and selecting text from a VBA macro! the
code I've been using is listed below and if anyone can have a look and
suggest a better way of doing this (and possibly one which works for XP) I
would be very grateful. This works fine in office 2k but XP is kicking me
up and down the house!
Cheers
John
p.s. I'm new to VBA and this isn't my code so I'm still a bit sketchy on how
all the selection thing works. Any pointers gratefuly accepted.
Public Sub AmendList()
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
Persname:
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.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
y = y + 1
If y = 20 Then GoTo endnow
If test <> test1 Then
If Right(Selection.Style, 5) = "Entry" Then
ListType(x) = Selection.Style
End If
End If
GoTo Persname
Else
End1:
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1,
Extend:=wdExtend
If StyleNow = "Persinits" Then
txtInits(x) = Selection.Text
ElseIf StyleNow = "Perstitle" Then
txtTitles(x) = Selection.Text
ElseIf StyleNow = "Persname" Then
txtpersname(x) = Selection.Text
ElseIf StyleNow = "Office" Then
txtOffices(x) = Selection.Text
ElseIf StyleNow = "Department" Then
txtDepartments(x) = Selection.Text
ElseIf StyleNow = "Email" Then
txtEmails(x) = Selection.Text
End If
Selection.MoveRight Unit:=wdCharacter, Count:=2
StyleNow = Selection.Style
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.MoveRight Unit:=wdCharacter, Count:=1,
Extend:=wdExtend
If Right(Selection.Style, 5) = "Entry" Then
ListType(x) = Selection.Style
End If
Selection.MoveRight Unit:=wdCharacter, Count:=2
End If
If test <> test1 Then s = 6
Next s
Next x
endnow:
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If StyleNow = "Persinits" Then
txtInits(x) = Selection.Text
ElseIf StyleNow = "Perstitle" Then
txtTitles(x) = Selection.Text
ElseIf StyleNow = "Persname" Then
txtpersname(x) = Selection.Text
ElseIf StyleNow = "Office" Then
txtOffices(x) = Selection.Text
ElseIf StyleNow = "Department" Then
txtDepartments(x) = Selection.Text
ElseIf StyleNow = "Email" Then
txtEmails(x) = Selection.Text
End If
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If Right(Selection.Style, 5) = "Entry" Then
ListType(x) = Selection.Style
End If
Selection.MoveRight Unit:=wdCharacter, Count:=2
End Sub