+ Reply to Thread
Results 1 to 13 of 13

Paste Picture Works When Stepping Through (Debug), But Not In Runtime

  1. #1
    Registered User
    Join Date
    04-17-2012
    Location
    New York, US
    MS-Off Ver
    Office 2007, 2010, 2016 (Office 365)
    Posts
    12

    Paste Picture Works When Stepping Through (Debug), But Not In Runtime

    I have the following piece of code. Basically what it does is, copying a range as a picture, add a chart object, pasting the picture to the chart, saving the picture, then loading this newly saved picture on the form.
    Everything works perfectly fine, besides the 'Paste' action that works perfect when debugging, but not in actual run.

    I tried already each and all of the following, with no results:
    • Application.Wait
    • DoEvents
    • Sleep (from the C runtime library)
    When debugging through, it takes a second for the paste to happen, so apparently, in runtime as soon it leaves the '.Chart.Paste' line to the DoEvents or Application.Wait line, I lost already the paste action.

    Please Login or Register  to view this content.
    Is there anything else to do to have the picture pasted and then proceed with the code?
    Last edited by Hello World; 09-01-2017 at 02:04 PM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Paste Picture Works When Stepping Through (Debug), But Not In Runtime

    All I can think of:


    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    04-17-2012
    Location
    New York, US
    MS-Off Ver
    Office 2007, 2010, 2016 (Office 365)
    Posts
    12

    Re: Paste Picture Works When Stepping Through (Debug), But Not In Runtime

    Isn't working either.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Paste Picture Works When Stepping Through (Debug), But Not In Runtime

    Sorry - that's all I could think of - is the copy working at that stage?

  5. #5
    Registered User
    Join Date
    04-17-2012
    Location
    New York, US
    MS-Off Ver
    Office 2007, 2010, 2016 (Office 365)
    Posts
    12

    Re: Paste Picture Works When Stepping Through (Debug), But Not In Runtime

    Yes, copy is working fine, but still not pasting in runtime, only when debugging.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Paste Picture Works When Stepping Through (Debug), But Not In Runtime

    Maybe:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-17-2012
    Location
    New York, US
    MS-Off Ver
    Office 2007, 2010, 2016 (Office 365)
    Posts
    12

    Re: Paste Picture Works When Stepping Through (Debug), But Not In Runtime

    throws error

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Paste Picture Works When Stepping Through (Debug), But Not In Runtime

    Uno Mas:

    Please Login or Register  to view this content.

  9. #9
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Paste Picture Works When Stepping Through (Debug), But Not In Runtime

    For this method, you might want to add a resizing routine.

    In the Userform:
    Please Login or Register  to view this content.
    In a Module:
    Please Login or Register  to view this content.

  10. #10
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Paste Picture Works When Stepping Through (Debug), But Not In Runtime

    To do it by the chart method:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    04-17-2012
    Location
    New York, US
    MS-Off Ver
    Office 2007, 2010, 2016 (Office 365)
    Posts
    12

    Re: Paste Picture Works When Stepping Through (Debug), But Not In Runtime

    Wow Kenneth! Simply adding the '.Activate' made it work!
    (not sure what you meant to accomplish with the module code before, as just with the .Activate, it works perfectly fine.)

    Kinda interesting, as the chart was either way selected and active before pasting onto, so not sure what the Activate helped here, but it helped in fact..
    My full code now is:
    Please Login or Register  to view this content.
    Thanks again Ken!
    Last edited by Hello World; 09-03-2017 at 01:49 PM. Reason: added the final code

  12. #12
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Paste Picture Works When Stepping Through (Debug), But Not In Runtime

    Activate and Select are sometimes needed for these types of things when one would think not.

    #9 uses API methods to use Excel's clipboard contents as the image, not an external file. So, one skips the need for the chart object and the external file.

  13. #13
    Registered User
    Join Date
    04-17-2012
    Location
    New York, US
    MS-Off Ver
    Office 2007, 2010, 2016 (Office 365)
    Posts
    12

    Re: Paste Picture Works When Stepping Through (Debug), But Not In Runtime

    Thanks Ken for the extra explanation.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Code works fine when stepping through code but Excel freezes if I run it without stepping
    By OldManExcellor in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-19-2016, 10:39 AM
  2. Replies: 1
    Last Post: 03-31-2015, 03:01 PM
  3. Open workbook works on stepping but not on execute
    By Wongadob in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-09-2015, 01:33 PM
  4. [SOLVED] Excel-to-eMail Code Works Only When Stepping Through
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-26-2014, 11:19 PM
  5. [SOLVED] Runtime error...53; unable to debug
    By vinay.kottur in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2013, 01:34 PM
  6. OpenText function in macro hangs unless stepping through code in debug
    By Part-Time Coder in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2009, 05:32 PM
  7. Code works when stepping through, but cuts out when run
    By Reenen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2005, 07:47 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1