Jump to content
Sign in to follow this  
Jacco

Word PasteSpecial method

Recommended Posts

Jacco

Hi everyone,

I am currently working on a script that copies content from one word file to the other. I am however only interested in the unformatted text, headers and different text layout is not good if this gets copied as well.

I know that there exists such a function, namely: PasteSpecial. Also the PasteAndFormat method looks promising. But after several attempts I am unable to properly do this.

This is a bit of the (working) code at the moment, it uses the regular paste method instead.

$OSOURWORDAPP.Selection.WholeStory
$OSOURWORDAPP.Selection.Copy
_WordDocClose($OSOURWORDDOC, 0)
$ODESTWORDAPP = _WordAttach($SDESTFILENAME, "FileName")
$ODESTWORDAPP.Selection.EndKey(6)
$ODESTWORDAPP.Selection.InsertBreak(2)
$ODESTWORDAPP.Selection.Paste

So far I have tried the following variants of the pastespecial without succes

$ODESTWORDAPP.Selection.PasteSpecial(2)
$ODESTWORDAPP.Selection.PasteSpecial(0,0,0,0,2)
$ODESTWORDAPP.Selection.PasteSpecial(0,false,0,false,2)
$ODESTWORDAPP.Selection.PasteSpecial.DataType = 2 (wouldn't compile)
$ODESTWORDAPP.Selection.PasteAndFormate(22)

Please note that the corresponding wdPasteText and wdFormatPlainText are 2 and 22 respectivly.

I have the feeling I am pretty close here, but can't seem to nail it down.

Thanks in advance. Any help is welcome.

Regards,

Jacco

Share this post


Link to post
Share on other sites
Juvigy

Try this one:

$ODESTWORDAPP.Selection.PasteSpecial()

Also did you try if it works if you do the same manually?

Sometimes the paste special function in Word/Excel stops working.

Share this post


Link to post
Share on other sites
Jacco

hi Juvigy,

Thanks for the reply! The code you suggested does work, but does nothing special, it is just like a regular paste now. I however have found out that headers are only copied if the source document has more than one section. Doing a simple find & replace removes all the sections. When it is then copied no header and footer information isn't copied with anymore. This more than sufficient for me.

_WordDocFindReplace($OSOURWORDDOC, "^b", "")

Later!

Edited by Jacco

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×