c# word copy and paste problem

G

guanfenglin

Hello guys,

I am writing a word automation in c#, however, when I merge 2 word
documents(copy and paste) it actually creates a new line after paste.
Is it possible to remove the next line (and how) or there is a proper
way to copy and paste?

thx alot!

James
 
C

Cindy M -WordMVP-

Hi James,
I am writing a word automation in c#, however, when I merge 2 word
documents(copy and paste) it actually creates a new line after paste.
Is it possible to remove the next line (and how) or there is a proper
way to copy and paste?
Hmmm. Emulating the user's actions (copy/paste, then backspace) isn't
really the most desirable, efficient or reliable method to automate
Word. If you're going to be doing a lot of this, then you need to learn
how to use Word's object model, otherwise you're in for a lot of
frustration and, possibly, angry users.

1. Did you test InsertFile before deciding on Copy/Paste? Or, if you're
dealing with two files that are already open on the UI, the
Range.FormattedText property? Either of these would be preferable to
copy/paste in most circumstances.

2. It would be more correct to delete a RANGE of characters, rather
than use "Backspace". There's really no way to guarantee that the
cursor is going to be where it is when you're testing. Much better
would be to ascertain the range (is this the end of the document, for
example?) and remove that.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
G

guanfenglin

Hi,

I am using word template files. so it creates a word doc from a
template file, loops thru all the fields, and then copy the content
from another template file.

Can you please recommend a link to teach me how to use the word object
correctly?

Regards

James
Cindy M -WordMVP- 写é“:
 
C

Cindy M -WordMVP-

Hi (e-mail address removed),
I am using word template files. so it creates a word doc from a
template file, loops thru all the fields, and then copy the content
from another template file.
Then you should look at using InsertFile, rather than copying.
Can you please recommend a link to teach me how to use the word object
correctly?
I recommend the word.vba.general newsgroup on this server. Not all of
the code posted there is "professional", but much of it is.

Other than that, "Writing Word Macros" from O'Reilly press and "Word
2000 VBA Programmer's Reference" from Wrox are good places to start. If
you read German "Word-Programmierung Das Handbuch" from MS Press is a
very good reference.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
G

guanfenglin

Hi Cindy,

thanks for your reply, can you please show me how to copy a range from
a doc to another doc without using the clipboard?

thanks alot.
 
C

Cindy M -WordMVP-

Hi (e-mail address removed),
can you please show me how to copy a range from
a doc to another doc without using the clipboard?
I showed you the basic code in my first reply: you need to
use the Range.FormattedText property. Please re-read point
1 in my first message to you.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

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