Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2011, 12:39 PM
Registered User
 
Join Date: Jul 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default VBA Word

Hi All,

Right so we get data from our sql box from there we format the data coming out using a template file? This works in all cases ie: Bold, Center, Line breaks page breaks blah blah...

We have a problem were the first loop works and the second loop leaves the LI and doesnt add the bullet points...

Can you help???

So the data looks something like this?
<ul>
<li>This is 1</li>
<li>This is 2</li>
<li>This is 3</li>
</ul>
Normal sentence
<ul><li>This is 1</li></ul>
<ul><li>This is 2</li></ul>
<ul><li>This is 3</li></ul>


Dim StartWord As String, EndWord As String, StartItem As String, EndItem As String

' Set Markup tags to search for, i.e. <ul></ul>, <li></li>
StartList = "?ul^0062"
EndList = "?^0047ul?"

StartItem = "?li^0062"
EndItem = "?^0047li?"

' Clear the existing Find criteria from the Selection
Selection.Find.ClearFormatting

' Set the Find criteria
With Selection.Find
.Text = StartList & "*" & EndList
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With

' Loop through results of find, modifying the formatting
While Selection.Find.Execute
Selection.Range.Select
Selection.Text = Replace(Replace(Selection.Text, "<ul>", ""), "</ul>", "")
Selection.Range.ListFormat.ApplyBulletDefault (wdWord9ListBehavior)

Dim r As Range
Dim orig As Range
Set r = Selection.Range
Set orig = Selection.Range
' Set the Find criteria for the List Items
With r.Find
.ClearFormatting
.Text = StartItem & "*" & EndItem
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
' Loop through results of find, modifying the formatting
End With
While r.Find.Execute And r.InRange(orig)
r.Select
Selection.TypeText Replace(Replace(r, "<li>", ""), "</li>", "")
Selection.TypeParagraph
Wend

Selection.Range.ListFormat.ApplyBulletDefault (wdWord9ListBehavior)
Wend




Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help in word VBA Premanshu Word VBA 3 June 26th, 2009 10:04 PM
word 2003 vba joukaniabhay VB How-To 0 February 15th, 2005 07:33 PM
vba and MS Word Earl G. Hyde VB How-To 0 December 27th, 2003 02:06 AM
Word VBA sdowen Excel VBA 4 December 3rd, 2003 04:32 PM
VBA Word gcookie79 Excel VBA 1 November 12th, 2003 01:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.