Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with DataObject.GetText

Status
Not open for further replies.

Petemush

Technical User
Jun 21, 2002
255
GB
This is partially connected to the folowing thread707-659257 , click to read what I'm actually trying to achieve!

The only problem I have with this code now is that when it runs I get the following error:

GetText Invalid FORMATETC structure

And the line highlighted is the line marked red below.

All my references are correct, really don't know what's wrong! By the wayy, all hopeandpray() does is keep a record of the previous active cell in the sheet "Sheet5"

Cheers,

Pete


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Call hopeandpray
Dim runCopy As Boolean, clipContents As String
Dim clipboardContents As DataObject

Set clipboardContents = New DataObject
clipboardContents.GetFromClipboard
clipContents = ""
clipContents = clipboardContents.GetText(1)

If Sheet5.Range("A1").Value = clipContents Then runCopy = True Else runCopy = False

If Range(&quot;A&quot; & Target.Row).Value <> &quot;&quot; Then
With ActiveSheet
.CommandButton1.Top = ActiveCell.Top + (((ActiveCell.Height) / 2) - (CommandButton1.Height / 2))
End With
End If
If runCopy Then
On Error GoTo noSelections
Sheet5.Range(&quot;A1&quot;).Copy
noSelections:
End If
End Sub
 
Try puting the line:
[blue]
Code:
  On Error Resume Next
[/color]

in front of the line:
[blue]
Code:
  clipContents = clipboardContents.GetText(1)
[/color]

The .GetText method fails when the clipboard is empty.

 
That solved the problem, thanks for that!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top