Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

Inserting a string at the end of a paragraph

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
alfonso gonzales - 13 Feb 2005 16:54 GMT
Hello Everybody,
I am making a macro to convert word pararaphs into html paragraphs.

So need to convert all the Word Paragraphs into HTML paragraphs. And then
purge the Word document of the Word paraqraph marks.
I can insert an opening marker <p> but seem to have a problem with inserting
the closing makrer.
so what I do is:

For Each Par in ActiveDocument.Paragraphs
Set myrange = Par.Range
myrange insertAfter "</p>"
Next

the problem with this is that the "</p>" gets inserted after the next
paragraph mark and not within the relevant paragraph. As a result it gets a
bit tough when I want to process these paragraphs further.

Any help apperciated.

alfonso gonzales
Jay Freedman - 13 Feb 2005 18:22 GMT
Hi Alfonso,

Don't try to handle this by inserting and deleting items individually.
Use the Find/Replace feature to replace all paragraph marks with the
combination </p><p>.

In the Replace dialog, you would put ^p in the Find What box and put
</p><p> in the Replace With box, and hit Replace All. Then you'll just
have to insert the <p> before the first paragraph and delete the extra
<p> at the end of the document.

In a macro, the code would look like this:

Sub foo()
   Dim oRg As Range
   Set oRg = ActiveDocument.Range
   With oRg.Find
       .ClearFormatting
       .Replacement.ClearFormatting
       .Text = "^p"
       .Replacement.Text = "</p><p>"
       .Format = False
       .Forward = True
       .Wrap = wdFindContinue
       .MatchWildcards = False
       .Execute Replace:=wdReplaceAll
   End With
   
   Set oRg = ActiveDocument.Range
   ' insert tag at beginning of doc
   oRg.InsertBefore "<p>"
   ' remove extra tag at end of doc
   ' (this works because the only ^p
   ' left in the doc is the one at
   ' the end)
   With oRg.Find
       .Text = "</p><p>^13"
       .Replacement.Text = "</p>^13"
       ' all other settings stay as before
       .Execute Replace:=wdReplaceAll
   End With
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org

>Hello Everybody,
>I am making a macro to convert word pararaphs into html paragraphs.
[quoted text clipped - 17 lines]
>
>alfonso gonzales
Klaus Linke - 23 Feb 2005 02:13 GMT
Hi Jay,

I wouldn't use ^13 in "Replace with"... it often inserts a character that looks like a paragraph mark, but doesn't work like one (= doesn't store the style and paragraph formatting). And the last paragraph mark even stores section and document formatting.

It might work, but just seems a bit risky ;-)

BTW, a wildcard replacement
 Find what: ([!^13]@)(^13)
 Replace with: <p>\1</p>\2
would also insert the tags.

Regards,
Klaus

> Hi Alfonso,
>
[quoted text clipped - 65 lines]
> >
> >alfonso gonzales
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.