locked
Word 2010 VBA - copy a page into the clipboard as an image RRS feed

  • Question

  • I'm using Word 2010 and have a multi-page document.

    Using VBA, I want to select a page and copy it to the clipboard as an image.   The external program I'm pasting into will only allow me to paste in images.

    I've been trying all kinds of things such as api's, saving the page first as a pdf then inserting it into a new doc and doing Selection.WholeStory and copying it (with this method the memory size of the contents of the clipboard are way too big), etc, etc.  None of these work very well.

    How can I:

    1.  Select a specific page of the document

    2.  Then copy the selected page to the clipboard in an IMAGE format?

    Thanks for your help in advance.

    Thursday, September 27, 2012 10:17 PM

All replies

  • Select a page -> Copy -> paste in a new doc as Picture -> then it is pasted as image.You can take the image to other app.

    PasteSpecial method's DataType argument should be picture type.Pls do a study on wdPasteDataType.


    Best Regards,
    Asadulla Javed, Kolkata
    ---------------------------------------------------------------------------------------------
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    Friday, September 28, 2012 9:55 AM
    Answerer
  • Sub CopyPage()
    On Error Resume Next
    ActiveDocument.Bookmarks("\page").Range.CopyAsPicture
    End Sub

    should do the trick for the page containing the cursor. You may have a problem with multiple elements on the page. Word documents comprise a number of story ranges or 'layers' which act independently - much like a pile of transparencies. You cannot process the story ranges as one in vba, so if what you want is not in the main page range you will not be able to copy it like this.


    Graham Mayor - Word MVP
    www.gmayor.com

    Friday, September 28, 2012 2:28 PM
  • Thanks for the suggestion.  I have tried all of the wdPasteDataTypes and only certain ones are available.  Using the ones that are available the header and footer are cut off.

    Also, pasting into Word isn't necessary (unless I need to do that to get the page to be an image and then reselect the image and copy it) because I'm pasting into another program as an image.

    Any other ideas?

    Friday, September 28, 2012 7:05 PM
  • Thanks for the suggestion.  I have tried this and the header and footer are cut off so the entire page is not there.  Also, I'm not sure it is just an image.  It took forever to paste it into Paint.net.

    Any other ideas?

    Friday, September 28, 2012 7:14 PM
  • I am not sure how your application will treat image in clipboard.I used another word for creating an image from a normal word window by PAsteSpecial.The image created now can be used in application.

    For example in MS Office Picture Manager you can paste the word craeted image as if normal image.

    I assume your application can treat an image object and convert in it's own style.But it definitely can't directly copy an word winow and paste as image.That's why I used a temp word for first converting a word window to image and then copying the image to your app.

    Hope I made clear.


    Best Regards,
    Asadulla Javed, Kolkata
    ---------------------------------------------------------------------------------------------
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    Saturday, September 29, 2012 5:31 AM
    Answerer
  • As I indicated in my earlier post, there are no 'pages' in a Word document, there are overlaid story ranges flowed between the current margins. It is not possible to grab the whole page using Word vba. You should however be able to do it with third party software. Install SnagIt and use vba to print the page in  question to its 'printer' driver, to output in any common graphics format that takes your fancy.

    Graham Mayor - Word MVP
    www.gmayor.com

    • Proposed as answer by 许阳(无锡) Monday, October 1, 2012 2:08 AM
    • Unproposed as answer by johnr2000 Monday, October 1, 2012 8:29 PM
    Saturday, September 29, 2012 6:12 AM
  • Hi johnr2000,

    Thanks for posting in the MSDN Forum.

    Like Graham mentioned, It is not possible to grab the whole page using Word vba. CopyAsPicture is too confusing to use it correctly.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 1, 2012 2:08 AM