Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Office > Word

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 02-16-2009, 08:57 AM
Novice
 
Join Date: Feb 2009
Posts: 1
pachmarhi is on a distinguished road
Default Looping macros to add text to beginning and end of a paragraph

I want to convert word documents to HTML and need to insert appropriate paragraph styles throughout. I found a macro to help me to add text to the beginning of the paragraph, but having difficulty getting it to do the same for the end. What can I add so that at the end of each paragraph formatted with Heading 2, it will insert </h1> before the paragraph mark?

'This example inserts "<h1>" at the beginning of
' every paragraph formatted with the Heading 2 style.
With ActiveDocument.Content.Find
.ClearFormatting
.Style = wdStyleHeading2
'The Do...Loop statement repeats a series of
' actions each time this style is found.
Do While .Execute(Forward:=True, Format:=True) = True
With .Parent
'If the found text is the last
' paragraph in the document...
If .End = ActiveDocument.Content.End Then
.StartOf Unit:=wdParagraph, Extend:=wdMove
.InsertAfter "<h1>"
Exit Do
'If the found text is *not* the last
' paragraph in the document...
Else
.StartOf Unit:=wdParagraph, Extend:=wdMove
.InsertAfter "<h1>"
.Move Unit:=wdParagraph, Count:=1
End If
End With
'Goes back to the beginning of the Do...Loop statement.
Loop
End With
Reply With Quote
Reply

Bookmarks

Thread Tools
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Paragraph Breaks In Mail Merge Fields SamuelT Word 0 09-25-2008 09:38 AM
can't delete paragraph mark at end of document kb Word 8 08-04-2006 09:09 PM
Looping though Custom Properties in VBA suekay Misc 0 05-19-2006 09:10 AM
Macros & Passwords paulrm906 Excel 0 03-04-2006 03:30 AM
Self Help Books for Macros? KRB Excel 0 11-22-2005 03:33 PM


All times are GMT -4. The time now is 11:42 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.