Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: Need an empty Paragraphs object in Word 2000

Status
Not open for further replies.

akb195

Technical User
Dec 9, 2003
8
US
Hi,

I need a temporary Paragraphs variable in some Word 2000 VB code to store a selection of paragraphs obtained from the ActiveDocument.Paragraphs object.

I am new to VB and so have this qn: I have declared the object but now I need to set a reference to it. Is there a default empty Paragraphs object I can use?

My code looks like

Dim para As Paragraph
Dim tempParas As Paragraph

Set tempParas ..... ?

For Each para In ActiveDocument.Paragraphs
If (some condition) Then
tempParas.Add(para)
End If
Next para

Thanks in advance.
 
In the VBA help take a look at Collection

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi akb195,

What exactly are you trying to achieve here?

Normally when working with Objects, all you have is a pointer. You can copy the pointer (into a Collection if you like) but it doesn't copy the object. If the original (and only) object (paragraph in your case) is later changed, the copied pointer points to the changed object. So, if your goal is to actually save copies of paragraphs you are most likely going to run into problems. You might also find Adding a paragraph to a (non-Document) Collection a trifle problematic.

The best place by far to save paragraphs is in a Document. Create a temporary document if necessary but, unless you are quite sure what you are working with, I would strongly recommend you don't try and manipulate stand-alone paragraphs.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
PHV - thanks for the suggestion. I had tried earlier but gave up. I looked again and the solution is to declare and create using New a Collection object instead of a Paragraphs object. This is what the code looks like:

Dim para As Paragraph
Dim tempParas As New Collection

For Each para In ActiveDocument.Paragraphs
If (some condition) Then
tempParas.Add(para)
End If
Next para
 
Hi Tony,

I thought I had it licked but sure enough I ran into the problems you referred to. What I am trying to do is lift sentences/paras from Document A that are formatted in a user-defined style and put them into Document B.

My current code has yet to create that new document and the approach I was taking was to store the pointers to the paras I want in a Collection and then start creating the new document B. I was able to Add the paras to the Collection object but I can't get them back! - the problem you referred to.

I would greatly appreciate any help - pointers, suggestions, code snippets or just the plain answer :)

Thanks,
akb195
 
Hi akb195,

how are you doing with this one? Did you find a solution?

I have some questions that may, with answers help point you.

Do you know what the user defined styles are? If you do, or can find out, then simply check each paragraph to see if it is one of them and extract it out into the new document.

However, post back if you have found a solution.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top