M
MKruer
I am working on a macro that will convert MS Word markup into a
BBCode. I have it partly working for list elements, but I cant seem to
figure out the rest. The problem is when it comes to multiple levels
of list elements, (see complex list below) Every time the bullets or
numbering changes or is indented, a new list element should be
generated. I am posting the MS word, the expected BBcode and the VB
code i am using. Any help will be appreciated.
Thank you
-Matt-
[MS word]
List Bullets
· One
· Two
· Three
List Numbers
1. One
2. Two
3. Three
List Letters
A. One
B. Two
C. Three
Complex List
1. One
a. One
b. Two
i. One
ii. Two
iii. Three
c. Three
2. Two
3. Three
[/MS word]
[expected BBCode]
List Bullets
List Numbers
List Letters
Complex List
[VB code]
Sub ConvertLists()
Dim lCnt As Long
Dim lLst As Long
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
lLst = rDcm.ListParagraphs.Count
For lCnt = lLst To 1 Step -1
With rDcm.ListParagraphs(lCnt).Range
.Select
If .Characters.Last.Previous <> "]" Then
.Characters.Last.InsertBefore "[/list]"
.InsertBefore "[*]"
.ListFormat.RemoveNumbers
End If
End With
While
Selection.Range.Paragraphs(1).Previous(1).Range.ListParagraphs.Count
<> 0
lCnt = lCnt - 1
With rDcm.ListParagraphs(lCnt).Range
.Select
.InsertBefore "[*]"
.ListFormat.RemoveNumbers
End With
Wend
Selection.Range.InsertBefore "
BBCode. I have it partly working for list elements, but I cant seem to
figure out the rest. The problem is when it comes to multiple levels
of list elements, (see complex list below) Every time the bullets or
numbering changes or is indented, a new list element should be
generated. I am posting the MS word, the expected BBcode and the VB
code i am using. Any help will be appreciated.
Thank you
-Matt-
[MS word]
List Bullets
· One
· Two
· Three
List Numbers
1. One
2. Two
3. Three
List Letters
A. One
B. Two
C. Three
Complex List
1. One
a. One
b. Two
i. One
ii. Two
iii. Three
c. Three
2. Two
3. Three
[/MS word]
[expected BBCode]
List Bullets
- One
- Two
- Three
List Numbers
- One
- Two
- Three
List Letters
- One
- Two
- Three
Complex List
- One
- One
- Two
- One
- Two
- Three
- Three
- Two
- Three
[VB code]
Sub ConvertLists()
Dim lCnt As Long
Dim lLst As Long
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
lLst = rDcm.ListParagraphs.Count
For lCnt = lLst To 1 Step -1
With rDcm.ListParagraphs(lCnt).Range
.Select
If .Characters.Last.Previous <> "]" Then
.Characters.Last.InsertBefore "[/list]"
.InsertBefore "[*]"
.ListFormat.RemoveNumbers
End If
End With
While
Selection.Range.Paragraphs(1).Previous(1).Range.ListParagraphs.Count
<> 0
lCnt = lCnt - 1
With rDcm.ListParagraphs(lCnt).Range
.Select
.InsertBefore "[*]"
.ListFormat.RemoveNumbers
End With
Wend
Selection.Range.InsertBefore "
- "
Next
End Sub
[/VB code]