+ Reply to Thread
Results 1 to 8 of 8

Use VBA to test if Windows Clipboard is empty?

  1. #1
    Forum Contributor
    Join Date
    09-21-2014
    Location
    Midwest USA
    MS-Off Ver
    2010
    Posts
    349

    Use VBA to test if Windows Clipboard is empty?

    How can I use VBA to test if the Windows Clipboard is empty? In the past I’ve use the code “Application.CutCopyMode” to test the Excel clipboard status – it returns 1 if the clipboard has contents and it returns 0 if empty. I have a situation that I copy data from Notepad to paste into Excel through an existing VBA application. I’m trying to add an error handling piece should the Windows clipboard it empty what the macro is ran. I discovered that while I can paste from Notebook, “Application.CutCopyMode” still returns a 0. So apparently I need a different way to test the Windows Clipboard than I do the Excel Clipboard. Would appreciate any suggestions. Thanks.

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,637

    Re: Use VBA to test if Windows Clipboard is empty?

    https://stackoverflow.com/questions/...before-pasting
    using this as base

    MS Forms object 2.0 library needs to be active in reference
    Please Login or Register  to view this content.
    ps my Forms 2.0 was missing from selectable list
    i had to manually add it to references ...\system32\FM20.DLL
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Forum Contributor
    Join Date
    09-21-2014
    Location
    Midwest USA
    MS-Off Ver
    2010
    Posts
    349

    Re: Use VBA to test if Windows Clipboard is empty?

    That does the trick - Thanks!

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

    Re: Use VBA to test if Windows Clipboard is empty?

    @ humdingaling

    MS Forms object 2.0 library gets loaded automatically the moment you add a userform to a file.
    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.

  5. #5
    Forum Contributor
    Join Date
    09-21-2014
    Location
    Midwest USA
    MS-Off Ver
    2010
    Posts
    349

    Re: Use VBA to test if Windows Clipboard is empty?

    Interesting you mention that bakerman2. I "thought" I had that library loaded, but when I first tried humdingaling's solution it err'd out - when I doubled checked, that library was missing and once added it worked. However, I have a dozen or so userforms in my personal.xlsb file which was open (although hidden) at the time. Do you have to have a userform in the given workbook that you want to use the library?

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

    Re: Use VBA to test if Windows Clipboard is empty?

    You don't have to keep the UF in it.
    You can delete the UF once the library is loaded and it stays loaded then.

  7. #7
    Forum Contributor
    Join Date
    09-21-2014
    Location
    Midwest USA
    MS-Off Ver
    2010
    Posts
    349

    Re: Use VBA to test if Windows Clipboard is empty?

    Is there a way to "accidentally" remove it? I'm pretty sure I had it - seems like I needed it for a different VBA solution in years past. I had to reload my PC at the end of last year, so it's possible that's when I lost it - just would be surprised if it's been missing that long without causing me a problem. I'll watch it now - see it it disappears again. Thanks for the info.

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,637

    Re: Use VBA to test if Windows Clipboard is empty?

    Thanks for the tip Bakerman - having it automatically load via userform would certainly help the fluffing around
    i think the part for me was i couldnt find it in my selectable list
    i had to go find the dll file to load it

    Aquixano - references are based per project/workbook
    this saves you having numerous references that you may or may not have used in the past transfering to projects that do not require it i guess

    ie i dont require outlook automation on every workbook so i wouldn't want it automatically drawing from other files which may be open
    "accidentally" adding some code that refers to this reference in the file and then having compatibility issues once i send that file to someone else who doesnt have outlook automation installed

+ 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. [SOLVED] How to copy value of selected cell to windows clipboard?
    By 1tane1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-21-2013, 07:51 AM
  2. VBA retrieve URL from Windows Clipboard
    By ACFeddes in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-23-2012, 05:32 PM
  3. Excel 2007 : Cannot empty clipboard
    By friebe13 in forum Excel General
    Replies: 1
    Last Post: 11-22-2011, 09:24 PM
  4. Test for Windows 7
    By Rhapsodie in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-03-2010, 07:30 AM
  5. Replies: 11
    Last Post: 11-18-2008, 11:20 AM
  6. Copy Values from cell to windows clipboard via Macro
    By hexbasher in forum Excel General
    Replies: 3
    Last Post: 08-18-2008, 10:41 PM
  7. Add method of SeriesCollection object clears Windows clipboard
    By Richo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-02-2006, 11:30 AM
  8. [SOLVED] Accessing Windows clipboard during runtime
    By Conan Kelly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2005, 05:05 PM

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