MyData.GetFromClipboard

hawley

Board Regular
Joined
Apr 7, 2002
Messages
197
I am trying to see if there is anything in the clipboard. The below code works when there is something in the clipboard but, if there is nothing I get a run time error on the bolded blue line of:
run time error'-2147221404(80040064)':
DataObject:GetText Invalid FORMATETC structure

Why is this and how can I change this so it won't blow up?
____________________________________
Dim MyData As New DataObject
Dim strClip As Variant

MyData.GetFromClipboard
strClip = MyData.GetText

If Not (IsNull(strClip)) Then
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End If
___________________________________________

Thanks in advance!!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try

If MyData.GetFromClipboard is nothing then
msgbox "Nothing in clipboard"
else
strClip = MyData.GetText
end if

If that doesn't work then try

On Error Resume Next

MyData.GetFromClipboard
strClip = MyData.GetText

If Err <> 0 then
msgbox "Nothing in clipboard"
else
end if

On Error Goto 0
 
Upvote 0
Thanks for the suggestions. Here is what happened.

First one:
I get a compile error on the bolded blue line:
Compile Error:
Expected Function or variable
_______________________________
Sub Format_Sheet()
Dim MyData As New DataObject
Dim strClip As String

If MyData.GetFromClipboard Is Nothing Then
msgbox "Nothing in clipboard"
strClip = MyData.GetText
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End If
_______________________________



Second one:
I get the same run time error as I got the last time.
run time error'-2147221404(80040064)':
DataObject:GetText Invalid FORMATETC structure
_________________________________________________
Dim MyData As New DataObject
Dim strClip As String

MyData.GetFromClipboard
strClip = MyData.GetText

If Err <> 0 Then
MsgBox "Nothing in clipboard"
Else
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End If

On Error GoTo 0
_________________________________________________________



I even tired a third option and get the same result as the first option.
________________________________________________________
MyData.GetFromClipboard
If (MyData.GetText) Is Nothing Then
strClip = MyData.GetText
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End If
________________________________________________________
 
Upvote 0
Dim MyData As New DataObject
Dim strClip As String

MyData.GetFromClipboard
strClip = MyData.GetText

If Err <> 0 Then
MsgBox "Nothing in clipboard"
Else
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
End If

On Error GoTo 0


You need to put On Error Rume Next to skip the error

Like

On Error Resume Next

MyData.GetFromClipboard
strClip = MyData.GetText

More code.
 
Upvote 0
Thank you!!! It is always the small things that get me. Here is what I ended up doing.
______________________________________
Sub Format_Sheet()
Dim MyData As New DataObject
Dim strClip As String
On Error GoTo NotText
MyData.GetFromClipboard
strClip = MyData.GetText
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
NotText:
'don't want anything to happen.
End Sub
___________________________________________
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,432
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top