Log in

View Full Version : Solved: Changing a bullet point list back into a paragraph



IanRob
04-26-2013, 01:48 AM
Hi

I have a Word document with a number of bullet point lists

I want to change the areas with bullet lists back into paragraphs

ie I want to find all CR Bullets and remove the CR bullet and replace with a space

I have found the following code on this forum which just replaces bullets with semi colons.
I would very much apprciate it if you could advise on how to change the code so that it removes the CR bullet and replaces with a space?

Many thanks - code below

Sub ReplaceBullets()
Dim oPara As Paragraph
Dim r As Range
For Each oPara In ActiveDocument.Paragraphs()
Set r = oPara.Range
If r.ListFormat.ListType = wdListBullet
Then
r.ListFormat.RemoveNumbers _
NumberType:=wdNumberParagraph
r.InsertBefore Text:=";"
End If
Set r = Nothing
Next
End Sub

fumei
04-26-2013, 10:09 PM
I want to change the areas with bullet lists back into paragraphs What makes you think they are not paragraphs? They most likely are paragraphs.

I want to find all CR Bullets and remove the CR bullet and replace with a space
Just replace the semi-colon with a space.

Sub ReplaceBullets()
Dim oPara As Paragraph
Dim r As Range
For Each oPara In ActiveDocument.Paragraphs()
Set r = oPara.Range
If r.ListFormat.ListType = wdListBullet Then
r.ListFormat.RemoveNumbers _
NumberType:=wdNumberParagraph
r.InsertBefore Text:=" "
End If
Set r = Nothing
Next
End Sub You do know that removing things changes the style format.

fumei
04-26-2013, 10:24 PM
Also, you do not actually need the range object.
Sub ReplaceBullets()
Dim oPara As Paragraph

For Each oPara In ActiveDocument.Paragraphs()
If oPara.Range.ListFormat.ListType = wdListBullet Then
oPara.Range.ListFormat.RemoveNumbers _
NumberType:=wdNumberParagraph
oPara.Range.InsertBefore Text:=" "
End If
Next
End Sub

IanRob
04-26-2013, 11:57 PM
Fumei

Thank you for the reply

In the document that I need to change, the bullet points are definitely not paragraphs. They are sentences within a paragraph. I know it sound odd, but that is the way it was constructed.

The paragraphs do not have bullets. They just have an extra line feed.

So I need to know how to alter the code to remove the CR that preceeds the bullet, as well as the bullet.

Thanks

fumei
04-27-2013, 08:43 PM
I am sorry but that does not make sense to me, and I can not construct things as you describe.

Bullet points are "definitely not paragraphs". No of course not. Bullets are bullets. But they are not sentences either.

"The paragraphs do not have bullets. " Huh Then what DOES have bullets?

"So I need to know how to alter the code to remove the CR that preceeds the bullet, as well as the bullet." So you want to end up with ONE long paragraph?

Is there any way you can post a document? Because this is not making sense to me. If I make a multi-line (but one paragraph) and I bullet it, there is only ONE bullet. The other lines do not have bullets.

IanRob
04-27-2013, 11:53 PM
Hi fumei

Thanks for you reply.

I apologise, I should have attached a sample of the document for you to see.

The document attached to this post is a sample of a number of much larger documents.

Each bullet point is a sentence within a paragraph, where the paragraphs are denoted either by an unbulleted spare line (or it could be a bulletted blank line)

In case you are wondering how the documented was created in that format, it is because I am writing a book, and I have found that it is easier to move sentences and blocks of sentences around if the chapters are constructed in this way.

Once the Chapter is finalised, I would obviously prefer not to have to manually remove all the CR bullets in order to reconstruct proper paragraphs again.

I hope the attachement makes the problem clearer.

Thanks again for your help

fumei
04-28-2013, 03:10 PM
Each bullet point is a sentence within a paragraph, where the paragraphs are denoted either by an unbulleted spare line (or it could be a bulletted blank line) Ummm, you may be well served if you understood the structure of Word more.

"Each bullet point is a sentence within a paragraph" No, you are incorect. They are, as I stated, separate paragraphs. Those are not CR, but CRLF.

I asked: "So you want to end up with ONE long paragraph?" You did not answer...so I am goling to assume that you in fact do want one long paragraph. That is what will happen if you remove the CRLF.
Sub ReplaceBullets()
Dim oPara As Paragraph

For Each oPara In ActiveDocument.Paragraphs()
If oPara.Range.ListFormat.ListType = wdListBullet Then
oPara.Range.ListFormat.RemoveNumbers _
NumberType:=wdNumberParagraph
oPara.Range.InsertBefore Text:=" "
oPara.Range.Text = Replace(oPara.Range.Text, Chr(13), "")
End If
Next
End Sub This will remove the paragraph marks (making one long paragraph). Note however, that it reverts each iteration back into a bullet. This is because of the way Word paragraph marks work. If they are removed, the paragraph takes the format structure of the following paragraph.
In case you are wondering how the documented was created in that format, it is because I am writing a book, and I have found that it is easier to move sentences and blocks of sentences around if the chapters are constructed in this way. Really? I have hard time believing you are serious. Would not using Outline view make things much easier? I have written two books and that is NOT a good way to do things...IMHO. But hey, if it works for you....shrug.

In any case...you may have a big problem if this really is how your document is structured.

"unbulleted spare line (or it could be a bulletted blank line)" Hmmmm. It is a bad idea to ever have these. FAR better to use styles properly. Doing this would probably help you with editing as well. Styles are how Word actually works.

What can I suggest? Do not try and do things by the whole document. Select your chunks defined by the gaps you have as "blank" paragraphs. Get your code to work on the chunk.

IanRob
04-29-2013, 08:44 AM
Fumei

Thank you for your updated code

With one small modification (changing "" to " " in the replace line) it does 95% of what I require.

If you run it on the sample, you will see that it leaves the paragraphs (albeit without a spare line)

I appreciate your time in altering the code

However, if you don't mind I will continue writing in the way that suits me best

Thanks again for your assistance on the code

fumei
04-29-2013, 03:24 PM
Oooops. Yes, you are quite correct about the " ".

And hey, do whatever you want regarding your own documents. My comments was simply that I thought it was a round about way of dealing with editing issues. Best wishes.

IanRob
04-29-2013, 11:07 PM
Hi fumei

Thanks for your comments

Could I ask one more question?

How do I alter the code to simply act on the current paragraph (i.e. up to the end of the current set of bullet points), rather than go through all paragraphs?

Your assistance would be much appreciated.

Thanks

Ian

IanRob
04-30-2013, 03:00 AM
Sorry - a quick correction to the previous post

I should have said that I want it to just act on the currently selected area

(I am still talking about paragraphs as my perception of the finished document rather than the way Word defines a paragraph)

In effect, I have taken your advice on chunking and altered the code to:

Sub ReplaceBullets()
Dim oPara As Paragraph

For Each oPara In Selection.Paragraphs()
If oPara.Range.ListFormat.ListType = wdListBullet Then
oPara.Range.ListFormat.RemoveNumbers _
NumberType:=wdNumberParagraph
oPara.Range.InsertBefore Text:=" "
oPara.Range.Text = Replace(oPara.Range.Text, Chr(13), " ")
End If
Next
End Sub

The problem I have right now is the one you mentioned previously in that the formating of the selected area is taken from the line above the selection, rather than the first line of the selection

Is there any way round that?

Thanks

fumei
04-30-2013, 08:21 PM
(I am still talking about paragraphs as my perception of the finished document rather than the way Word defines a paragraph) I really think you are hampered by this. Word does not give a hoot about anyone's perception of paragraphs. You are working with Word VBA, and VBA only acts as it is told to do, within the way Word VBA defines paragraphs.

That said, it may help if you post a document as it IS, with a section showing how you WANT it to be. We can start with that. I am not really sure what how you want things to end up.

As a further note, you could be avoiding a great big whack of grief if you used proper styles.

IanRob
05-01-2013, 06:24 AM
Hi

Thanks for your patience

As requested, I have attached a document with two sample pages showing the before and after situation.

Just to clarify, most chapters in the book make extensive use of styles and I am consistently using Outline mode of display.

There are a small number of chapters where I have struggled to get a number of key facts in the correct logical sequence, so they have been written in the form where every sentence in each paragraph has been made into a bulleted line (in effect a Word bulleted paragraph)

I now wish to convert the bullet areas back to the “normal” style and in effect change the chr$(13) back into Chr$(32)

I was hoping to have a simple macro to do that for me. Ideally, it would convert what ever area had been highlighted, whether that be a section or a whole chapter.

Thanks

fumei
05-02-2013, 09:25 PM
For a SELECTION of your bullets, try:
Sub ReplaceBullets()
Dim lngCount As Long
Dim var

lngCount = Selection.Paragraphs.Count
For var = lngCount - 1 To 1 Step -1
If Selection.Paragraphs(var).Range.ListFormat.ListType = wdListBullet Then
Selection.Paragraphs(var).Range.ListFormat.RemoveNumbers _
NumberType:=wdNumberParagraph
Selection.Paragraphs(var).Range.Text = _
Replace(Selection.Paragraphs(var).Range.Text, Chr(13), " ")
End If
Next
Selection.Paragraphs(1).Range.ListFormat.RemoveNumbers
End Sub

Yes, it sure would be nice to run through a bunch of paragraphs, but unfortunately this will only work for a "set" of bullets. It will NOT work if any other paragraphs are included. That is, unless you are using proper styles, which you are not using. Then it may be possible, although quite complicated..

BTW when you make a selection it very important you include the paragraph mark at the end of the last bulleted paragraph.

IanRob
05-02-2013, 10:45 PM
Fumei

Thanks for that solution

It is exactly what I was looking for

Again, thank you for your patience and perseverance

fumei
05-03-2013, 11:01 AM
You are welcome. If you are satisfied please mark the thread as Solved.

IanRob
05-03-2013, 10:42 PM
fumei

It should already be marked as solved with a 5 star rating

Thanks again