Help With Macro WordList to BBCodeList

M

MKruer

This is the next item in my Word2Bbcode Macro. I need to take a window
list and convert it into the Bbcode equivalent. Right now it will
convert the bullet, and the numbers, but it convert the letters to
numbers as well. And I need to encapsulate all items in the list
between
  • and [/list[ tags.

    Once again any help would be appreciated.

    Thanks

    -Matt-

    Examples and Correct equivalent BBCode

    List Bullets
    · One
    · Two
    · Three

    List Bullets
    • One
    • Two
    • Three

    List Numbers
    1. One
    2. Two
    3. Three

    List Numbers
    1. One
    2. Two
    3. Three

    List Letters
    A. One
    B. Two
    C. Three

    List Letters
    • One
    • Two
    • Three

    Code:
    Private Sub ConvertLists()
    Dim para As Paragraph
    For Each para In ActiveDocument.ListParagraphs
    With para.Range
    For i = 1 To .ListFormat.ListLevelNumber
    If .ListFormat.ListType = wdListBullet Then
    .InsertBefore "[*]"
    ElseIf .ListFormat.ListType = wdOutlineNumbering Then
    .InsertBefore "[1]"
    Else
    .InsertBefore "[a]"
    End If
    Next i
    .ListFormat.RemoveNumbers
    End With
    Next para
    End Sub
 
H

Helmut Weber

Hi Matt,

what is that BBCode?

Whatever it is, converting word lists
to a third party format seems to be endlessly complicated.

· Eine Liste
· Eine Liste
· Eine Liste
a) Eine Liste
b) Eine Liste
c) Eine Liste
1. Eine Liste
2. Eine Liste
3. Eine Liste

According to your code:
There is no list of type wdOutlineNumbering at all.
So all lists of a type unequal to wdListBullet are tagged,
not to speak of unwanted multiple taggings.

My input is to be seen above.

Your code produces the following output:

[*]Eine Liste
[*]Eine Liste
[*]Eine Liste
[a][a]Eine Liste
[a][a]Eine Liste
[a][a]Eine Liste
[a][a][a]Eine Liste
[a][a][a]Eine Liste
[a][a][a]Eine Liste

Which is miles away from what is should do.
Either you make it an obsession, or you leave it.

It must be possible, yes,
but it'll be a horrible exercise.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

MKruer

BBCode is short for Bulletin Board code.
http://www.phpbb.com/phpBB/faq.php?mode=bbcode

Quote:
BBCode is a special implementation of HTML. Whether you can actually
use BBCode in your posts on the forum is determined by the
administrator. In addition, you can disable BBCode on a per post basis
via the posting form. BBCode itself is similar in style to HTML: tags
are enclosed in square braces [ and ] rather than < and > and it offers
greater control over what and how something is displayed. Depending on
the template you are using you may find adding BBCode to your posts is
made much easier through a clickable interface above the message area
on the posting form. Even with this you may find the following guide
useful.

Its essentially like a light weigh HTML where only a few tags apply. If
you ever use vbulletin phpbb or any of the other numerous website
bulletin boards out there, all of them support it. It was a way for
each board to prevent HTML tags from breaking the site if there was a
malformed code injection.

Currently BBCode only have very limited tags,

Bold, Italic, Underline, Font Size (thanks to you I have this now),
Lists, Color, URL's, and Image.

These are all the official ones.
 
H

Helmut Weber

Hi Matt,

so that nobody could say I didn't try,
here are my thoughts,
still it's be a horrible exercise.

This is my input:


• Eine Liste¶
• Eine Liste¶
• Eine Liste¶

a) Eine Liste¶
b) Eine Liste¶
c) Eine Liste¶

1. Eine Liste¶
2. Eine Liste¶
3. Eine Liste¶


These are unfinished thoughts on how to approach the task:

Sub Macro10()
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 "
  1. "
    Next
    End Sub

    This is my output:

    1. Eine Liste¶
    2. Eine Liste¶
    3. Eine Liste

    1. Eine Liste¶
    2. Eine Liste¶
    3. Eine Liste

    1. Eine Liste¶
    2. Eine Liste¶
    3. Eine Liste



    There are of course lots of possible complications,
    and lots of things still to do,
    e.g. getting the kind of numbering.

    Whenever there is a select command,
    it's for testing only.
    If tests with selection are alright
    then we could rewrite it to using ranges.


    Happy thinking!

    --
    Greetings from Bavaria, Germany

    Helmut Weber, MVP WordVBA

    Win XP, Office 2003
    "red.sys" & Chr$(64) & "t-online.de"
 
M

MKruer

Sorry for the delay in writing back, I have been busy with other work.
I took a look at the code, and it quite effective for simple lists, but
when if comes to larger and more complex lists it starts to break down.

Formatting aside, I wonder if there is a way to detect the First Indent
Line, and use it instead of the paragraph returns. This is a tough nut
to crack mainly because we don't have direct access to the word code
like we had in Word 6.0
 
H

Helmut Weber

Hi,
I wonder if there is a way to detect the First Indent Line,
and use it instead of the paragraph returns. < ??
This is a tough nut to crack

indeed.

Numbering is a problematic field.
Specially, if you're talking about outline numbered lists,
which may be interspersed with bodytext.

Like I said, must be doable.
Devote half of your life to it or leave it.

I'm sorry.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

MKruer

I think I might have a better way to do it but I don't know if it is
feasible. Right now we are going line by line and replacing the bullets
with text. Why? Why not just replace the existing bullets with
"[*]" that will remove one major obstacle. The next issues are
finding where a list begins and ends, and what type of list is it. I
created a few macros to test various aspects of the word lists. Let me
know what you think.

-TIA-

Sub Macro10()
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
' If ActiveDocument.Lists(1).Range.ListParagraphs Then
' Selection.Range.InsertBefore "
  1. "
    ' ElseIf ActiveDocument.Lists(2).Range.ListParagraphs Then
    ' Selection.Range.InsertBefore "
    • "
      ' Else
      ' Selection.Range.InsertBefore "
      • "
        ' End If
        Next
        End Sub

        Sub Macro11()
        Set mytemp = ActiveDocument.ListTemplates(1)
        For Each lev In mytemp.ListLevels
        lev.NumberStyle = wdListNumberStyleLowercaseLetter
        Next lev
        End Sub
        Sub Macro12()
        Set LT = ActiveDocument.ListTemplates.Add(OutlineNumbered:=True)
        For x = 1 To 9
        With LT.ListLevels(x)
        .NumberFormat = "
      • "
        End With
        Next x
        Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=LT
        End Sub
        Sub Macro13()
        Dim i As Integer
        Dim s As String
        Dim lst As ListParagraphs
        s = ""
        For i = 1 To ActiveDocument.Lists.Count
        Set lst = ActiveDocument.Lists(i).Range.ListParagraphs
        s = s & "List " & Format$(i) & ": " & lst.Count & " paragraphs" &
        vbCrLf
        Next i
        MsgBox s
        End Sub
 
H

Helmut Weber

Hi Matt,
I think I might have a better way to do it but I don't know if it is
feasible. Right now we are going line by line and replacing the bullets
with text. Why? Why not just replace the existing bullets with
"[*]" that will remove one major obstacle. The next issues are
finding where a list begins and ends, and what type of list is it. I
created a few macros to test various aspects of the word lists. Let me
know what you think.

I think, you are already more expert, when it comes to lists,
than I ever will be in this specific field,
and you are on the right track, IMHO.

I'd better ask _you_ about lists than you asking me.

All I can do is suggest to start some new threads
about the problems in detail,
like where does a list start and where does it end
and what type is it.

This needs more than a bit of code put together in a lunch break,
and there are people around here which may know better than me.


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

MKruer

Hi Helmut,

I don't know anything I just like to pretend I do. That's not
entirely true, I have never been good at programming from the ground
up, but I have always been very good at analyzing code and tweaking it
(sometimes so much that it is not distinguishable from the original) I
also seem to be gifted (or that's what some of my friends say) when
it comes to new ideas and creative solutions for solutions. I somehow
manage to avoid group think mentality. Even if you can help me
directly I still want to bounce ideas off you to see if you see some
fundamental error in my code or perhaps have a more efficient way of
doing it. My programming tends to heavily lean towards a brute force
approach.


Helmut said:
Hi Matt,
I think I might have a better way to do it but I don't know if it is
feasible. Right now we are going line by line and replacing the bullets
with text. Why? Why not just replace the existing bullets with
"[*]" that will remove one major obstacle. The next issues are
finding where a list begins and ends, and what type of list is it. I
created a few macros to test various aspects of the word lists. Let me
know what you think.

I think, you are already more expert, when it comes to lists,
than I ever will be in this specific field,
and you are on the right track, IMHO.

I'd better ask _you_ about lists than you asking me.

All I can do is suggest to start some new threads
about the problems in detail,
like where does a list start and where does it end
and what type is it.

This needs more than a bit of code put together in a lunch break,
and there are people around here which may know better than me.


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top