none
Excel CopyPicture Method fails in VB RRS feed

  • Question

  • The following line of code is failing in VB

    xlSheet.UsedRange.CopyPicture(Excel.XlPictureAppearance.xlPrinter, Excel.XlCopyPictureFormat.xlBitmap)

    The following does work:

    xlSheet.UsedRange.CopyPicture(Excel.XlPictureAppearance.xlScreen, Excel.XlCopyPictureFormat.xlBitmap)

    All the Enumerations are correct.  Why does the first one fail?  The error is "CopyPicture method of Range class failed"

    Thanks

    EM
    Thursday, September 3, 2009 2:32 AM

Answers

  • Actually I just realized that

    xlSheet.UsedRange.CopyPicture(Excel.XlPictureAppearance.xlPrinter, Excel.XlCopyPictureFormat.xlBitmap)

    likely fails as Excel does not provide the Bitmap option when copying with the "As shown when printed" option.  It automatically defaults to the Picture format.  I am assuming the following will work:

    xlSheet.UsedRange.CopyPicture(Excel.XlPictureAppearance.xlPrinter, Excel.XlCopyPictureFormat.xlPicture)

    I will get back and confirm.

    Thanks

    EM
    • Marked as answer by Bessie Zhao Tuesday, September 8, 2009 4:19 AM
    Thursday, September 3, 2009 4:08 PM

All replies

  • Anyone know the answer to this?

    Thanks

    EM
    Thursday, September 3, 2009 2:54 PM
  • Actually I just realized that

    xlSheet.UsedRange.CopyPicture(Excel.XlPictureAppearance.xlPrinter, Excel.XlCopyPictureFormat.xlBitmap)

    likely fails as Excel does not provide the Bitmap option when copying with the "As shown when printed" option.  It automatically defaults to the Picture format.  I am assuming the following will work:

    xlSheet.UsedRange.CopyPicture(Excel.XlPictureAppearance.xlPrinter, Excel.XlCopyPictureFormat.xlPicture)

    I will get back and confirm.

    Thanks

    EM
    • Marked as answer by Bessie Zhao Tuesday, September 8, 2009 4:19 AM
    Thursday, September 3, 2009 4:08 PM
  • Hi EM,

    You are right.

    In my side, I have made a test using this.UsedRange.CopyPicture(Excel.XlPictureAppearance.xlPrinter, Excel.XlCopyPictureFormat.xlPicture), and it does not throw an exception.

    Best regards,
    Bessie
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Proposed as answer by Paolo Marani Friday, October 20, 2017 1:49 PM
    • Unproposed as answer by Paolo Marani Friday, October 20, 2017 1:50 PM
    Tuesday, September 8, 2009 4:19 AM
  • I've experienced the same problem.

    it is related to excel not able to handle clipboard properly under the account where excel is running.

    If you run excel on server side, you should configure with DCOMCNFG the "Microsoft Excel Application" ole server, giving a local administrator account. Also, if you are running a desktop process (with excel running at user level) you can try to make Excel explicitly VISIBLE (Application.Visible=True).

    Hope this helps,

    Paolo Marani

    Friday, October 20, 2017 2:01 PM