+ Reply to Thread
Results 1 to 13 of 13

VBA Excel code to Clear all in Clipboard

  1. #1
    Registered User
    Join Date
    12-20-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    16

    Lightbulb VBA Excel code to Clear all in Clipboard

    Hi All,

    I'm trying to write a macro to "clear all" in the excel Clipboard.

    It's effect should be equivalent to going to the ClipBoard and clicking 'Clear All' (refer to below screenshot)

    http://imgur.com/a/7d8M7

    The point of this is clear all clipboard data at the end of a very long macro i have designed, which will not prompt the "the picture is too large and will need need to truncated" once closing the workbook.

    I have spent hours trying to find a solution but nothing have been successful.

    The below is a common solution where you paste this code after "pasting a value." I have tried this, but the data still seems to be put onto the clipboard.
    Application.CutCopyMode = False

    Is there a way to simply code a "Clear All" command as per the screenshot?

    Seems simple, but struggling to find the answer.

    Thank you all!

    - James

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA Excel code to Clear all in Clipboard

    Why not find the last used cell in column A and copy the cell below it?
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    12-20-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    16

    Re: VBA Excel code to Clear all in Clipboard

    I just realised that the clipboard is not part of excel, it is the window's clipboard, hence why I can't code it in excel.

    The below is the relative coding., even with the Application.CutCopyMode = False, it still seems to put the copied data onto the clipboard.


    Sheets("Pivot").UsedRange.Select
    Selection.Copy
    Sheets("Final").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: VBA Excel code to Clear all in Clipboard

    .
    ..
    Does this help ?

    http://http://stackoverflow.com/ques...board-with-vba

    Saw this on another post, and I have tested it with Word VBA.

    'Clearing the Office Clipboard

    Dim oData As New DataObject 'object to use the clipboard

    oData.SetText text:=Empty 'Clear
    oData.PutInClipboard 'take in the clipboard to empty it
    Just copy and paste into your code where ever you need to clear the Clipboard.

    Another thing I noticed is that when I .Quit a program, say Excel, it keeps asking me if I want to keep the data is the Clipboard. A work around is to clear the clipboard using the above stated code. See below:

    'Clearing the Office Clipboard

    Dim oData As New DataObject 'object to use the clipboard

    oData.SetText text:=Empty 'Clear
    oData.PutInClipboard 'take in the clipboard to empty it


    'You can also just remove the Alert Messages from the Excel Program while
    'the code is running
    'Remove alert Messages from the Excel Program when closing
    ExcelProgram.DisplayAlerts = False

    'Quiting the Excel Application
    ExcelProgram.Quit
    I used the above example in a VBA code to import data from an Excel File. See here


    This functionality is held within the library "Microsoft Forms 2.0 Object Library". To link to that library go to the VBA editor, then Tools, References and pick it out from the list if it's not already ticked.

    You can do more funky stuff with a bunch of WinAPI calls, but I generally prefer avoiding those unless absolutely necessary.

    Also, don't forget about the DisplayAlerts property, which will suppress dialog boxes - although I'm not sure if it would always produce the desired result.

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: VBA Excel code to Clear all in Clipboard

    Hi jduong,

    Try the following code:
    Please Login or Register  to view this content.
    It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
    Please Login or Register  to view this content.
    This option requires all variables to be declared and will give a compiler error for undeclared variables.

    Lewis

  6. #6
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: VBA Excel code to Clear all in Clipboard

    .
    .
    .

    Just located this ... tested and works :

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-20-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    16

    Re: VBA Excel code to Clear all in Clipboard

    This worked! thanks so much

  8. #8
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: VBA Excel code to Clear all in Clipboard

    Your welcome. Thanks for the add rep.

    Merry Christmas !

  9. #9
    Registered User
    Join Date
    12-22-2017
    Location
    Brasil
    MS-Off Ver
    2010 Pro
    Posts
    1

    Re: VBA Excel code to Clear all in Clipboard

    No above option works in Windows 10Pro with Excel 2016.
    Does anyone have any idea on how to clear windows clipboard using Excel VBA macro programming?

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA Excel code to Clear all in Clipboard

    E.Lulai F., welcome to the forum.

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  11. #11
    Registered User
    Join Date
    06-05-2019
    Location
    France
    MS-Off Ver
    2013
    Posts
    3

    Re: VBA Excel code to Clear all in Clipboard

    Hello everyone,

    The Logit's code don't work with me.
    So, after a long research, here a code I found wich is working well for me (Windows 10):

    Please Login or Register  to view this content.
    To call in your macro with :

    Please Login or Register  to view this content.
    Have a good day,

    Baboutz
    Last edited by Baboutz; 10-30-2020 at 10:23 AM.

  12. #12
    Registered User
    Join Date
    01-08-2021
    Location
    Germany
    MS-Off Ver
    365
    Posts
    1

    Re: VBA Excel code to Clear all in Clipboard

    Dear Baboutz,

    I have Win10 and Office365.

    I get various error messages, if I just copy your text into the VBA area. Is there a certain region within VBA where the information for the function is stored?
    Many Thanks!

  13. #13
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: VBA Excel code to Clear all in Clipboard

    Quote Originally Posted by Kingrat View Post
    Dear Baboutz,

    I have Win10 and Office365.

    I get various error messages, if I just copy your text into the VBA area. Is there a certain region within VBA where the information for the function is stored?
    Many Thanks!
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ 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. Clear the clipboard
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-24-2008, 08:38 AM
  2. How to clear the clipboard contents in VBA
    By Wilbur in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2006, 10:10 AM
  3. What VBA activitys clear the clipboard?
    By Marie J-son in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-27-2006, 04:05 PM
  4. VBA Clear clipboard
    By NickH in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-13-2005, 02:10 PM
  5. [SOLVED] Clipboard clear
    By Reuel in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-24-2005, 01:05 PM
  6. [SOLVED] Clipboard Clear API error
    By G-Force in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-18-2005, 04:05 PM
  7. [SOLVED] Clear and control the Office clipboard in Excel
    By quartz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-22-2005, 05:06 PM
  8. [SOLVED] Do you wish to clear clipboard memory?
    By WendyUK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2005, 10:06 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