Consulting

Results 1 to 8 of 8

Thread: Clearing clipboard performance

  1. #1

    Clearing clipboard performance

    Hi,

    Question from me this time.

    For years I've been running a small macro that adds a new row to a listobject (table), then copies some information from the currently selected row and pastes that into the new row.

    After that, I clear the clipboard using Application.CutCopyMode = False

    The last couple of weeks, this routine became sluggish, so I decided to investigate which commands were responsible for the slowness. Lo and behold, this statement alone:

    Application.CutCopyMode = False

    takes 1.9 seconds and is responsible for almost all of the execution time!

    I've replaced it with the silly Sendkeys "{ESC}", which is instantaneous.

    Has anyone else seen this happen?
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    This is an interesting question, are you able to create a file that has this issue?

    I would be interested to see what was on the clipboard at the point Application.CutCopyMode = False is run.

    The only thing i can think of is that the clipboard contains a lot of data when it is run and takes time to empty, have you tried making a small sub to only clear the clipboard, then run the problem code after when the clipboard is empty?
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  3. #3
    I just tried, copying the entire table then using cutcopymode and subsequently copying just a single cell.
    There is a slight difference, but "just" 20% on 0.02 seconds.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  4. #4
    When I copy the table to a fresh workbook, all seems well. But then again, even the original workbook now performs as I expect it to. I have no idea what is going on.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  5. #5
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    I was thinking that the clipbord could have been full from previous work that has been completed, I mean very full. When you run your code, it takes a while to clear the clipboard. When you run it for the second time, the clipboard is fairly empty so runs fast.

    This is just my thought process.

    Maybe you could remember if you were doing a lot of copy/ pasting before you run the code with the issue, or maybe runing code that does not clear the clipboard?
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  6. #6
    Could be, I was also using a virtual machine at the time, so perhaps VMWare is at play here. Thanks!
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    In

    ' By Chip Pearson
    ' chip@cpearson.com
    ' www.cpearson.com/Excel/Clipboard.aspx
    ' Date: 15-December-2008


    Chip uses

    Private Declare PtrSafe Function EmptyClipboard Lib "user32" () As Long

    to clear the Clipboard




    I'm not sure if CutCopyMode clears the clipboard also


    https://learn.microsoft.com/en-us/of...6)%26rd%3Dtrue

    Application.CutCopyMode property (Excel)

    Returns or sets the status of Cut or Copy mode. Can be True, False, or an XLCutCopyMode constant, as shown in the following tables. Read/write Long.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    Thanks Paul.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

Posting Permissions

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