PDA

View Full Version : Solved: Change bullets to Normal and insert HTML tag



Designergrrl
02-10-2009, 06:04 PM
Hi;

I'm trying to write a macro that will search the document for any bulleted or numbered lists, insert the HTML List Item tag before each paragraph in the list, then convert the paragraph's Style to Normal.

I do not need to insert Unordered List tags before and after the set of bullets, but it would be a nice-to-have. Further, I plan to display this text dynamically in Flash, which does not support Ordered Lists, so that's why I'm planning to convert numbered lists into Unordered.

So... my problem is that I can certainly find a specific Style by its name, but I can't guarantee that all the documents I receive will have used the same Style to create these lists. Is there a way I can find Lists or paragraphs with ListFormat?

Thanks in advance for any help.

--DG

Nelviticus
02-11-2009, 03:33 AM
Damn, that's a lot harder than it looks! If the document has been formatted using styles then you can test whether each paragraph's Style.Type is wdStyleTypeList and/or test whether Style.ListTemplate isn't Nothing and isn't 'None'. However, if list formatting has been applied directly to the text without using styles it gets a lot harder and I haven't been able to figure out how to do it. Would love to see someone else's solution!

fumei
02-11-2009, 09:58 AM
Absolutely correct. It would be difficult. No matter what Microsoft says, using Word in any HTML kind of way is looking for trouble.

"convert the paragraph's Style to Normal." And why are you doing this?

Designergrrl
02-11-2009, 10:56 AM
Absolutely correct. It would be difficult. No matter what Microsoft says, using Word in any HTML kind of way is looking for trouble.

"convert the paragraph's Style to Normal." And why are you doing this?
All I really need to do is add the HTML List Item tag. I will be converting the entire document to plain-text at some point, so the bullet list will be eliminated at that point anyway. Still, I'd prefer to see it without the bullet character after the tag is inserted.

I've been combing around in the Help. I found a snippet that I think will help. It begins with "For Every li in ActiveDocument.Lists" My hang-up after that is how to tell Word to move the cursor to that li. (if that's even possible). I'm pretty new at VBA, so I just don't know what to do next.

Specifically, what I'd like to do is:
find a list in the active document
select the first item in the list
convert the item's style to Normal
collapse the selection to the beginning of the paragraph
insert the HTML List Item taglather, rinse and repeat until all list items in the document are processed.

Hope that clarifies

fumei
02-11-2009, 11:06 AM
Have you tried recording a macro?

Designergrrl
02-11-2009, 12:10 PM
Have you tried recording a macro?

Yeah, but when I did, I used Search and Replace and just looked for text with a specific Bullet style applied, so no joy there. Got another idea of what to search for?

Nelviticus
02-12-2009, 02:18 AM
Aha, well in that case you can use this:
Private Sub ListTest()

Dim aList As List
Dim aPara As Paragraph

For Each aList In ActiveDocument.Lists
For Each aPara In aList.ListParagraphs
With aPara.Range
.Style = "Normal"
.Text = "<li>" + .Text
End With
Next
Next

End Sub
Regards

Designergrrl
02-16-2009, 06:18 AM
Thanks for the help Nelviticus... here's what I ended up with:


For Each para In ActiveDocument.ListParagraphs
With para.Range
.Select
With Selection
.StartOf Unit:=wdParagraph, Extend:=wdMove
.InsertBefore ("<li>")
End With
.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
End With
Next