Copying text from one section of a document to another??

M

ML

I need a means in VBA or similar to copy all text from a user entered
section of a document to another section of the same document and preserve
all formatting and text. Is this possible?
I had been using the STYLEREF for this but the problem is I may have
multiple paragraphs in the section with the given style and it seems
STYLEREF only copies the last paragraph of text.
 
D

Doug Robbins

With VBA, you can use Range.FormattedText

For example, if you had a bookmark name "target" where you want the text to
be replicated and that text was selected, you could use

ActiveDocument.Bookmarks("target").Range.FormattedText =
Selection.Range.FormattedText

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

ML

So the only way would be with a bookmark?
The issue is the user is going to type this text and it may be too easy for
them to delete the bookmark I would think when they start typing.
 
D

Doug Robbins

The bookmark was at the location to which you wanted the text copied, not
the location at which the user would type the text. The user would have to
select the text that was to be copied.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

ML

Ok thanks. This needs to be as automated as possible so selecting the text
is not really an option.
 
J

Jonathan West

Hi ML,

A bookmark isn't necessary. What *is* necessary is a completely unabiguous
means of defining the source and destination locations. if you can do that,
then you can define Range object variables that mark them, and so do the
copy using the FormattedText method.

Before anybody can give you a code sample for that, we need you to see if
you can describe the source and destination locations.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
M

ML

The destination I can mark with anything required as the user does not edit
anything near the location. The issue is the source which must allow for
user content. What options are there for marking it that can then be
selected with a range?
 
J

Jonathan West

ML said:
The destination I can mark with anything required as the user does not
edit anything near the location. The issue is the source which must allow
for user content. What options are there for marking it that can then be
selected with a range?

Most elements within a document have a Range property. Every Character,
Word, Sentence, Paragraph, Table, Row, Cell has a range. For instance, if
you can define the source text as occupying the first paragraph of the first
cell of the second row of the first table in the document, then we can code
that and do the transfer.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
M

ML

Well, the section I want to copy will have a specific style used for the
text it encompasses. There may be other styles within but the start and end
should be the style I want. Is it possible to select all of this?
 
T

Thirsty_4_knowledge

I am trying to do the same thing -

My document is split up by each page being a seperate section (to achieve
different headers/footers per page). I want to dump EVERYTHING from the 2nd
section/page on into the 1st section. Or would it be easier to just delete
the section breaks automatically somehow...

Thanks for your time!
 

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