+ Reply to Thread
Results 1 to 7 of 7

VBA Image Not Successfully Copying (Intermittent Error)

  1. #1
    Registered User
    Join Date
    01-16-2014
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    25

    Unhappy VBA Image Not Successfully Copying (Intermittent Error)

    Hi All,

    I'm getting an error when running a code, but only intermittently. The run-time error code is 4605 (this method or property is not available because the Clipboard is empty or not valid).

    The error largely happens at a point where I'm trying to paste an image of a signature into a bookmark in a Word doc. Debug of error below.

    Debug Code Screenshot.jpg

    The unusual thing is that often this all works fine. Usually after hitting the error, I stop, run again, and it will run successfully. I have also found that it seems to happen more when I'm looping through the code multiple times, and there are multiple documents open. I had wondered whether the copy function is being slowed down and can't operate in time to successfully grab / copy the image perhaps. However I'm really not sure. Just wondered if anyone else had ever encountered this issue, and had any pointers?

    Many thanks in advance.

    Skins

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,026

    Re: VBA Image Not Successfully Copying (Intermittent Error)

    It is mostly likely a timing issue. Try pausing and/or clearing the clipboard before each operation.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Re: VBA Image Not Successfully Copying (Intermittent Error)


    Or try directly without any useless object variable SigBM# …
    Last edited by Marc L; 10-16-2021 at 11:01 AM.

  4. #4
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,234

    Re: VBA Image Not Successfully Copying (Intermittent Error)

    I encountered the described problem several times when copying from Excel and pasting into a Word document or a Power Point slide. The tests I performed showed that the second attempt was usually successful. Wait, Sleep, DoEvents did not help to solve the problem.

    Try a code construction similar to the following
    Please Login or Register  to view this content.
    Artik

  5. #5
    Registered User
    Join Date
    01-16-2014
    Location
    London, England
    MS-Off Ver
    Office 365
    Posts
    25

    Re: VBA Image Not Successfully Copying (Intermittent Error)

    Thanks all - adding in a wait of 1 second seems to have done the trick (although does slow this down slightly as it's part of a loop so can add around a minute or two to the process depending on the number in the loop). That said, it's better than having it fail. It seems that you can't add in a wait any less than one second? I also cleared the clipboard between each copy / paste as suggested. Thanks for the suggestions @ByteMarks.

    @Mark L - I'm not sure how I would do this directly without the object variable. The images are dynamic (or should I say the reference to the image within the workbook changes depending upon other variables - i.e. if "John Smith" is selected, the signature to send to the Word doc is Picture 3). Unless I'm misunderstanding your point here (which is more than possible)?

    @Artik - Thanks for the suggestions. Will give this a go - although will likely need to remove the message boxes as I anticipate this could end up popping up several times throughout the process.

    Cheers All

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA Image Not Successfully Copying (Intermittent Error)


    Quote Originally Posted by Skins11 View Post
    @Marc L - I'm not sure how I would do this directly without the object variable. The images are dynamic (or should I say the reference to the image within the workbook changes depending upon other variables - i.e. if "John Smith" is selected, the signature to send to the Word doc is Picture 3). Unless I'm misunderstanding your point here (which is more than possible)?
    No need to create any object variable to only use it once, waste of time & ressources ! Just use directly the object …

  7. #7
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,234

    Re: VBA Image Not Successfully Copying (Intermittent Error)

    Quote Originally Posted by Skins11 View Post
    @Artik - Thanks for the suggestions. Will give this a go - although will likely need to remove the message boxes as I anticipate this could end up popping up several times throughout the process.
    The Copy2BMK function tries to copy up to 10 times. Earlier I mentioned that in general the second attempt to copy was successful. So I gave quite a reserve. The message will appear only after the tenth unsuccessful attempt to copy the specified signature. So I hope that the message will never appear (although I also had random cases that this method sometimes did not work).

    Artik

+ 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. Intermittent VBA error on pasting
    By Throughstream in forum Excel General
    Replies: 2
    Last Post: 03-30-2020, 02:40 PM
  2. Intermittent Table Macro error
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-30-2019, 01:59 PM
  3. Replies: 6
    Last Post: 07-31-2018, 08:14 AM
  4. Intermittent Unspecified Runtime Error
    By Rclay11541 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-28-2016, 05:05 PM
  5. SQL job completing successfully but throwing the error
    By manjulabaadal in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 1
    Last Post: 01-23-2014, 09:16 AM
  6. Insert Pic Intermittent runtime error
    By vamosj in forum Access Programming / VBA / Macros
    Replies: 0
    Last Post: 04-19-2009, 07:01 AM
  7. [SOLVED] Error Handling - On Error GoTo doesn't trap error successfully
    By David in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 02:10 PM

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