How to make Copy of Paragraph to process in code

S

sippyuconn

I am trying to save a copy of a Paragraph to process later when
I loop to new paragraph

I tried this but get an error
LastPara = para

Is there another way to do this ???




Dim doc As Word.Document
Dim para As Word.Paragraph
Dim LastPara As Word.Paragraph


Set doc = ActiveDocument
For Each para In doc.Paragraphs
'Put the code here to manipulate the paragraph

LastPara = para

Next
 
J

Jialiang Ge [MSFT]

Hello sippyuconn,

I notice that you have posted an unmanaged post, "Trying to save copy of
Paragraph-For Each para In doc.Paragraphs". Do you mind if we continue the
post in this thread?

In VBA, the correct way to assign an object is to use keyword "Set", thus
your code "LastPara = para" should be modified as "Set LastPara =para".

Actually, the code "Set LastPara =para" will only assign a reference,
instead of a copy, of para to LastPara. In order to have a copy of
Word.Paragraph, you may try the following approaches:

Approach 1: use copy and paste. But the potential problem in this approach
is that it may replace the original content in your clipboard.
para.Range.Copy
Set LastPara = doc.Paragraphs.Add
LastPara.Range.Paste

Approach 2: write a Duplicate method yourself to copy each property of
Paragraph because Word.Paragraph does not provide such a method.
¡­¡­
LastPara.LeftIndent = para.LeftIndent
¡­¡­
LastPara.Range = para.Range.Duplicate
¡­¡­

Please let me know if you have any other concerns, or need anything else.
Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jialiang Ge [MSFT]

Hi sippyuconn,

Would you mind letting me know the result of the suggestions? If you need
further assistance, feel free to let me know. I will be more than happy to
be of assistance.

Have a great day!

Sincerely,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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