+ Reply to Thread
Results 1 to 20 of 20

Any Code for Clearing the Clipboard After Paste...?

  1. #1
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Any Code for Clearing the Clipboard After Paste...?

    Hi all,

    Anyone know if, in Excel (or in Windows in general, for that matter), there's a way to dump the clipboard AFTER AN INITIAL paste (like a "paste once" only kinda thing)? Say, I copy the word "cool" from some non-office App, then paste it in a WS. After successfully pasting this, I need an empty clipboard... It appears I ask the impossible.

    Thanx,
    Frith

    CP Link (per forum rules):
    http://www.mrexcel.com/forum/showthread.php?p=2732988
    Last edited by frith; 05-29-2011 at 07:18 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Any Code for Clearing the Clipboard After Paste...?

    EmptyClipboard

    Within Excel, you can clear Excel data from the clipboard with: Application.CutCopyMode = False. Or to completely clear the clipboard, use code like the following.

    Please Login or Register  to view this content.

    The Public Declare lines of code need to be in the declarations section of the module, before and outside of any procedure. If you are going to use this code within an object module (ThisWorkbook, a Sheet module, a UserForm module, or a Class module), change Public to Private.


    Courtesy of Chip Pearson

    http://www.cpearson.com/excel/Clipboard.aspx


    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Any Code for Clearing the Clipboard After Paste...?

    Hi,

    I pasted that code in, under General/Declarations, with macro security set to low, but am still able to paste as the day is long. The only thing I can think of is that I'm using Excel 2002... BTW, what/where do I place/do with that "Application.CutCopyMode = False"?

    Thanx,
    Frith

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Any Code for Clearing the Clipboard After Paste...?

    Setting Application.CutCopyMode does not affect what is in the clipboard.

    Excel behaves differtly in cut mode, copy mode and neither. (for example the crawly lines around the copied cells). That variable defines that behaviour not the contents of the clipboard.

    One could (perhaps) clear the clipboard after each paste, but why?
    You'd loose the capability to UnDo, you'ld loose the capbality to paste the same data to different part of the worksheet.
    I don't see any value other than to punish a clumsy fingered user (like me).

    If the goal is to protect the secrecy of the data coming from the clipboard, forget it. Excel is not a secure application. If you want to keep data a secret, keep it far away from Excel.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Any Code for Clearing the Clipboard After Paste...?

    As mikerickson says, why would you want to do this?

    However, try this example:

    Please Login or Register  to view this content.

    Assuming you copy and paste the code into a standard module, it will be in the clip board.

    The first paste special will paste the code into the workbook. The second paste, after the column is deleted,won't paste anything in.

    Best way to test this is to step through it with F8

    Regards

  6. #6
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Any Code for Clearing the Clipboard After Paste...?

    Hi,

    After pasting that code, there's no change in Excel's behavior, in A1 or elsewhere (tried low security, that public/private, declaration/worksheet thing, but nothing).

    Basically, what I need -- and, yes, there is a "reason" for all of this -- is for Excel to simply act as if I just double-clicked cell Y after pasting in cell Z (i.e., clearing the clipboard, greying out the paste option, etc.) Actually, you'd think this would be on the simpler side of what's solved here.

    Maybe this is more of a "Windows" issue, rather than an "Excel" one? I know there's Apps out there that will do this for me. Though, this is more of a last resort, as I really don't want my clipboard wiped out while using other Apps.

    Thanx,
    Frith
    Last edited by frith; 05-29-2011 at 08:02 AM.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Any Code for Clearing the Clipboard After Paste...?

    What can I say?

    I have opened Excel 2003 and Excel 2007 and, in each case, pasted the code into an empty standard module and then stepped through it using F8. In both cases, it pastes the code starting in cell A1, clears it and then doesn't paste anything ... because it's just been cleared.

    If it doesn't do that for you ... I cannot offer any other suggestions.

    We seem to be going through a loop here with me testing it and saying it works and you testing it and saying it doesn't.

    If there are apps out there that do what you want, it may be helpful to me and to others who may want to make use of it, if you shared the details and/or links.

    Regards

  8. #8
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Any Code for Clearing the Clipboard After Paste...?

    Got it!! Well, 99%... I just need it to trigger RIGHT AFTER I make each initial data paste (per instance of copy/paste)... You see, all data will come from outside Excel: I copy a word from a 3rd party App, then paste it into Excel. 1 hour later, I repeat the process. This is my job. It is during this interveining hour that no paste can occur!!! (And there IS a reason for this).

    Any ideas on how to do this without having to go to Tools / Macro / Run after each paste (at least that's what Excel 2002 is making me do)?

    Thanx,
    F

    Please Login or Register  to view this content.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Any Code for Clearing the Clipboard After Paste...?

    Assuming you paste with Ctrl+V, in ThisWorkbook,
    Please Login or Register  to view this content.
    In a code module,
    Please Login or Register  to view this content.
    Completely untested ...
    Last edited by shg; 05-29-2011 at 01:39 PM. Reason: Deactivate, not Open ...
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Any Code for Clearing the Clipboard After Paste...?

    Actually, I'm using another macro to "auto-paste on left-click". As you can see, I'm wanting to left-click on the A range -- say, A1 -- thereby pasting my copied data, then have NOTHING paste when I immediately/subsequently click on, say, A2. That's ALL I'm trying to do here. Of course, the below code works perfcectly fine, except for the fact that I keep having to do the whole "Tools / Macros / Run" thing, which pretty much defeats the purpose (i.e., I might as well just double-click on B1 to clear the clipboard. Feel me now? ...Sorry, I should have mentioned that "paste macro", but I thought it was here nor there.

    Thanx again,
    Frithlethrend


    Please Login or Register  to view this content.

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Any Code for Clearing the Clipboard After Paste...?

    If you're pasting in a macro, then clear the clipboard in the macro after pasting.

  12. #12
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Any Code for Clearing the Clipboard After Paste...?

    [FONT="Arial"]
    Quote Originally Posted by shg View Post
    If you're pasting in a macro, then clear the clipboard in the macro after pasting.
    I'm sorry? I just want to be able to auto-paste ONCE (via that lower part of the code I posted), and then have the clipboard CLEARED immediately thereafter (via that upper part of the code I posted), so that NOTHING gets pasted until I copy text again (I can do that now, but -- again -- I'm forced to click through "Tools / Macro /Macros / run", which is pointless. IOW, I want to trigger the upper part of that code upon execution of the lower part... This "sounds" like it should be simple enough to do.

    Thanx for replying,
    Frith

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Any Code for Clearing the Clipboard After Paste...?

    I think shg was agreeing with you that it is a simple task ... and expected you to add the line of ocde yourself ;-)

    Please Login or Register  to view this content.

    Regards

  14. #14
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Any Code for Clearing the Clipboard After Paste...?

    TMS, I haven't been following this thread closely, but might that not be simplified?

    Please Login or Register  to view this content.
    On Error GoTo 0 clears any current error, so there's no need to both clear the error and then reset error handling, and error handling (but not the current error, so clearing it is good) resets when you exit the sub.

    I guess it's application-dependent whether you clear the clipboard irrespective of whether you paste anything.
    Last edited by shg; 05-29-2011 at 05:31 PM.

  15. #15
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Any Code for Clearing the Clipboard After Paste...?

    Thanx, but I just get "named argument not found" errors whenever I click a cell...
    Last edited by shg; 05-29-2011 at 05:45 PM. Reason: deleted spurious quote

  16. #16
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Any Code for Clearing the Clipboard After Paste...?

    @shg: in all honestly, I don't know where is best to put the call. The code could probably be more efficient but I tend to leave OP code alone unless it is *really* bad (IMO).

    @frith: I suspect that the ClearClipboard definitions and code need to be in a standard module rather than in the sheet code module.

    In the majority of cases, you are more likely to get an early resolution of your question or problem if you post a sample workbook so the code can be seen and tested in context.

    Regards

  17. #17
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Any Code for Clearing the Clipboard After Paste...?

    I changed
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Reckon that should be changed back.

  18. #18
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Any Code for Clearing the Clipboard After Paste...?

    Hey guys, this is from another post @: http://www.mrexcel.com/forum/showthr...56#post2733556.

    It's a round-about way of doing what I need, but I would just need to be able to have the option of selecting the cell on the "second" attempt. That is, as I say, I select A1, the cursor gets bumped down to A2 (per below code). Though, if I select A1 a "second" time, the cursor remains on A1 (per normal routine). You see, this would dump the clipboard, like a double-click would do... Though, it is a shame I can't get the original plan to work (trigger the dump via macro-enabled paste execution).

    Thanx again,
    Frith

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    05-26-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Any Code for Clearing the Clipboard After Paste...?

    Guys, forget it, I JUST GOT IT (just saw your update, shg). Thank you both so much!!

    Can only pay ya'll back with karma,
    Frith

  20. #20
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: Any Code for Clearing the Clipboard After Paste...?

    @frith: you're welcome.

    If we have managed to address your problem, please mark your thread as Solved. See my signature for details or the FAQ.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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