Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7170111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:08:46+00:00 2026-05-28T15:08:46+00:00

I’m using code like this to get text from off the Clipboard. Dim DataObj

  • 0

I’m using code like this to get text from off the Clipboard.

Dim DataObj As New MSForms.DataObject
DataObj.GetFromClipboard
myString = DataObj.GetText

I use error handling to get the past the case where the Clipboard is empty, and everything is fine as long as I keep Error Trapping set to Break on Unhandled Errors.

However, for unrelated reasons I want to set Error Trapping to Break on All Errors, and this throws an error at DataObj.GetText when it finds the empty Clipboard. Is there any kind of test I can apply further upstream to avoid trying to process an empty Clipboard?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:08:47+00:00Added an answer on May 28, 2026 at 3:08 pm

    Handle the errors with On Error GoTo as shown here:

    Sub GetClipBoardText()
       Dim DataObj As MSForms.DataObject
       Set DataObj = New MsForms.DataObject '<~~ Amended as per jp's suggestion
    
       On Error GoTo Whoa
    
       '~~> Get data from the clipboard.
       DataObj.GetFromClipboard
    
       '~~> Get clipboard contents
       myString = DataObj.GetText(1)
       MsgBox myString
    
       Exit Sub
    Whoa:
       If Err <> 0 Then MsgBox "Data on clipboard is not text or is empty"
    End Sub
    

    You will notice that it will handle an empty clipboard as well.

    NB: to make the code work, you must have a reference to "Microsoft Forms 2.0 Object Library" (this file can be found at C:\windows\system32\FM20.dll on 32-bit machines, or at C:\Windows\sysWOW64\FM20.dll on 64-bit machines), otherwise you’d get the error "User-Defined type not defined".

    You can empty the clipboard before testing the above code by using the code below. Please paste it in a module.

    Private Declare Function OpenClipboard Lib "User32.dll" _
    (ByVal hWndNewOwner As Long) As Long
      
    Private Declare Function EmptyClipboard Lib "User32.dll" () As Long
     
    Private Declare Function CloseClipboard Lib "User32.dll" () As Long
     
    Public Sub ClearClipboard()
        Dim Ret
      
        Ret = OpenClipboard(0&)
        If Ret <> 0 Then Ret = EmptyClipboard
        CloseClipboard
    End Sub
    

    EDIT: you may also determine if the clipboard is empty by using this code:

    Private Declare Function CountClipboardFormats Lib "user32" () As Long
    
    Sub Sample()
        If (CountClipboardFormats() = 0) = True Then
            MsgBox "Clipboard is empty"
        Else
            MsgBox "Clipboard is not empty"
        End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a bunch of posts stored in text files formatted in yaml/textile (from
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.