Jump to content

Word PasteSpecial method


Jacco
 Share

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...