S
Scott Sipe
I'm converting lists to text and am running into a weird problem where
SOMETIMES a space (spacelike?) character appears.
The goal of my program is to take an AutoNumbered list like:
1. The first item
2. The second item
and turn it into plain text that looks like:
<ListItem>1.\tThe first item
<ListItem>2.\tThe second item
The code I have below does that absolutely fine. BUT, if you change the tag
(just change both instances of "<ListItem>" to something like "ListItem:"
then some weird space/not-space (it seems to be character 32, but
behaves..oddly) appears between the colon and the item number. It occurs
WHEN pasting..I just don't get it, it's very weird. Any thoughts?
thanks much,
Scott
Code below:
Sub TagLists()
Dim li As List
Dim ap As Paragraph
'
' Do the tagging
'
For Each li In ActiveDocument.Lists
For Each ap In li.ListParagraphs
ap.Range.InsertBefore "<ListItem>"
Next ap
Next li
'
' Change to text
'
ActiveDocument.ConvertNumbersToText
'
' Go re-arrange the lines
'
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<ListItem>"
.Forward = True
.Wrap = wdFindStop
End With
While Selection.Find.Execute
'
' Get before the "<ListItem>" tag and select to the beginning of the line
'
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
' MsgBox "Selection = >" & Selection.Text & "<" & vbCr & _
' "Length = >" & Selection.Characters.Count & "<" & vbCr
Selection.Cut
Selection.Find.Execute
Selection.Move Count:=1
Selection.Paste
Wend
End Sub
SOMETIMES a space (spacelike?) character appears.
The goal of my program is to take an AutoNumbered list like:
1. The first item
2. The second item
and turn it into plain text that looks like:
<ListItem>1.\tThe first item
<ListItem>2.\tThe second item
The code I have below does that absolutely fine. BUT, if you change the tag
(just change both instances of "<ListItem>" to something like "ListItem:"
then some weird space/not-space (it seems to be character 32, but
behaves..oddly) appears between the colon and the item number. It occurs
WHEN pasting..I just don't get it, it's very weird. Any thoughts?
thanks much,
Scott
Code below:
Sub TagLists()
Dim li As List
Dim ap As Paragraph
'
' Do the tagging
'
For Each li In ActiveDocument.Lists
For Each ap In li.ListParagraphs
ap.Range.InsertBefore "<ListItem>"
Next ap
Next li
'
' Change to text
'
ActiveDocument.ConvertNumbersToText
'
' Go re-arrange the lines
'
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<ListItem>"
.Forward = True
.Wrap = wdFindStop
End With
While Selection.Find.Execute
'
' Get before the "<ListItem>" tag and select to the beginning of the line
'
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
' MsgBox "Selection = >" & Selection.Text & "<" & vbCr & _
' "Length = >" & Selection.Characters.Count & "<" & vbCr
Selection.Cut
Selection.Find.Execute
Selection.Move Count:=1
Selection.Paste
Wend
End Sub