content lost during copy paste operation

N

Nishanth

Hi,
I have a vb application in which I am opening 2 word documents and then
cutting some formatted content from 1 file and pasting into the other word
file(along with the format).
If the user has opened any other document on his system and copies some
content to the clipboard then the current content is lost. If anybody has
come across this kind of situation and has some alternatives to copying and
pasting approach then it would be very helpful.

Thanks for the help.
 
C

Chuck

If your app copies then pastes how does the user have time/ability to do a
copy between your app's copy/paste operations? If you want the material you
copy to the clipboard in your app to persist after your procedure is
finished, then you could paste the content to a "holding document" which your
app could refer to later.

Posting code would would be helpful.
 
H

Helmut Weber

Hi Nishanth,

the alternative would be, not to copy anything at all,

but e.g. inserting a range's formatted text from doc1 into doc 2.

See the posting:
Is it possible Inserting a Range object at a specified location

from 5/5/2205.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
N

Nishanth

Hi,
I have 2 documents from which I am trying to move some formatted text.
Below is the code for the same.
The code fails with the error "Type mismatch" (Previously I was using
the clipboard but now I have changed it to the following code)

Dim rngWindowTable As Range 'This range is from the source document
Set rngWindowTable = objWordWindowTable.Selection.Range
Dim rngWindow As Range 'This range is from the target
document
Set rngWindow = objWordWindow.Selection.Range
objWordWindow.Selection.FormattedText = rngWindowTable
 
H

Helmut Weber

Hi Nishanth,

you have to show us more of your code, I think.
What is objWordWindow?

For some kind of copying a table plus formatting
from one doc to another, try:

Dim doc1 As Document
Dim doc2 As Document
Set doc1 = Documents("testdoc1.doc")
Set doc2 = Documents("testdoc2.doc")
Dim r1 As Range
Dim r2 As Range
Set r1 = doc1.Tables(1).Range.FormattedText
Set r2 = doc2.Range
doc2.Range.FormattedText = r1

Note that this example would replace the mainstory
in doc2 with the first table form doc1.

And that if the docs are created from different templates
which contain paragraph styles with the same names but
different definition, and if these styles are used in the
table 1, the formatting in doc2 may be different accordingly.
Probably will.

Can't test all right now.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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