VBA Paragraph Object?

J

John

Hi there,

I had a bit of code that I've used in PowerPoint to loop through each
paragraph in a textbox so that I could then extract the first sentence (ie
up to the first dash). Works fine, but trying to do the same thing in
Publisher, I discovered that "Paragraph" isn't an object of Textrange (as it
is in PowerPoint) so I'm having trouble getting hold of each paragraph.

This is the code from PowerPoint:

For Each txtPara In shp.TextFrame.TextRange.Paragraphs

and this is my (not quite working!) attempt in Publisher:
n = 1
Do Until shp.TextFrame.TextRange.Paragraphs(Start:=n) Is Nothing
strDelimiter = " " & Chr(45) & " "
arrHd = Split(shp.TextFrame.TextRange.Paragraphs(Start:=n).Text,
strDelimiter)
hdrsCol.Add (strHd)
n = n + 1
Loop

Can anyone suggest a good way to approach this?

Thanks

John
 
E

Ed Bennett

John said:
I had a bit of code that I've used in PowerPoint to loop through each
paragraph in a textbox so that I could then extract the first
sentence (ie up to the first dash). Works fine, but trying to do the
same thing in Publisher, I discovered that "Paragraph" isn't an
object of Textrange (as it is in PowerPoint) so I'm having trouble
getting hold of each paragraph.

Hi John,

Firstly, there is a .programming newsgroup for VBA and object model-related
issues.

If your news server does not carry it, then try subscribing to
news://msnews.microsoft.com instead.

You don't post your Publisher version - or whether you have the latest
service packs. Publisher 2003 has vastly superiod VBA to Publisher 2002.

The Paragraphs method will never return Nothing, so your Do Until will
become an infinite loop.

Once the end of the text box has been reached, the method will always return
empty paragraphs. However, in Publisher, nothing is empty. An empty
paragraph actually contains a Chr(13).

You could implement some kind of counter - 5 consecutive Chr(13) paragraphs
means that the text box is finished and the loop exits. Or if you have no
blank lines in your text boxes, you could just Do Until paragraphObject.Text
= Chr(13)
 
J

John

Thanks Ed,

Regarding the newsgroup, I'm using OE6 and could see it in my list, but due
to your prompt have discovered what Reset List button does, so thanks!

Thanks also for the advice about Paragraphs and bad loops. I'll have a go
with your suggestion.

Best regards

John

(PS Am using 2003 + about to be SP1!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top