Run-time error using clipboard

E

EllenM

Hello,
I am trying to restrict users that use my form to assigning only text data
to a string variable when the source of this data is from the clipboard. As
you know, the Windows clipboard can hold image data as well. SEE CODE BELOW
including my comment on line 7.


Private Sub Paste_Click()
Dim MyData As DataObject
Dim Num as integer
Dim myStr As String
Set MyData = New DataObject
MyData.GetFromClipboard
myStr = MyData.GetText ‘’’ ON THIS LINE YOU CAN SEE WHERE PROBLEM MIGHT
PRESENT THEMSELVES

Sub



Unfortunately, I am not aware of any controls to prevent the user from
storing something other than text to the clipboard and then later trying to
assign that data to a string variable. As such, I am susceptible to receiving
the following message during runtime.


Run-time error '-2147221504 (80040064)':

DataObject:GetText Invalid FORMATETC structure



In the above example I tested to see if I would get an error message if I
copied image data to the clipboard and assign it to a text variable. And sure
enough, I did.

If there a way to filter out this error message?

Thanks,
 
R

Russ

Ellen,
You might try putting gettext into a variant variable and use the TypeName()
function to see if it is a string.
There are also a VarType() function and an IsObject() function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top