Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:14 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.