Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Praha
    Posts
    988
    Thanks
    56
    Thanked 105 Times in 90 Posts

    Test for empty clipboard ?

    My code module, which includes a paste command, fails if the Clipboard is empty.

    I know how to trap/circumvent the error, but would rather test the Clipboard to see if it empty - but I don't know how to do that.

    Help appreciated.

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    This may work:

    Code:
    If Application.ClipboardFormats(1) = -1 Then
    MsgBox "Clipboard is emtpy - Nothing to paste!"
    else
    ActiveSheet.Paste
    End If
    Though this may be more reliable (though traps does not avoid the error):

    Code:
    On Error Resume Next
    ActiveSheet.Paste
    If Err Then 
    MsgBox "Clipboard is emtpy - Nothing to paste!"
    Err.Clear
    End If
    On Error Goto 0
    Steve
    Last edited by sdckapr; 2011-05-05 at 06:20.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2004
    Location
    Praha
    Posts
    988
    Thanks
    56
    Thanked 105 Times in 90 Posts
    Thank you.

    I have implemented your first suggestion - I dislike blanket error-handling as it can conceal problems one hadn't anticipated.

  4. #4
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts
    In the 2nd solution, I forgot to put error handling back on after the code is run (I modified the code)...

    Steve

Posting Permissions

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