J
John Keith
I want to use the followiong method to take text data from the
clipboard and insert it into a cell. I found the following code on
this website (authored by cpearson):
http://www.officekb.com/Uwe/Forum.aspx/excel-prog/153040/clipboard-excel
' Declarations -- above and outside of any procedure
Public Declare Function EnumClipboardFormats Lib "user32" ( _
ByVal wFormat As Long) As Long
Public Declare Function OpenClipboard Lib "user32" ( _
ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Declare Function GetClipboardFormatName Lib "user32" _
Alias "GetClipboardFormatNameA" ( _
ByVal wFormat As Long, ByVal lpString As String, _
ByVal nMaxCount As Long) As Long
Public Declare Function IsClipboardFormatAvailable Lib "user32" ( _
ByVal wFormat As Long) As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Sub TestForText()
Dim R As Range
Dim DataObj As MSForms.DataObject
Dim L As Long
Const CF_TEXT As Long = 1&
Set R = Range("A1")
Set DataObj = New MSForms.DataObject
L = IsClipboardFormatAvailable(CF_TEXT)
If L <> 0 Then
' text is available
DataObj.GetFromClipboard
R.Value = DataObj.GetText
Else
Debug.Print "text not available"
End If
End Sub
I pasted the above code into a module but when I run it I get this
error message:
User-defined type not defined on the Dim DataObj As MSForms.DataObject
statement
I'm not sure I handled the declarations correct, "above and outside of
any procedure", the code posted hee is exactly what I copied from the
module.
Any suggestions on how I can get the text pulled from the clipboard?
Thanks
John Keith
(e-mail address removed)
clipboard and insert it into a cell. I found the following code on
this website (authored by cpearson):
http://www.officekb.com/Uwe/Forum.aspx/excel-prog/153040/clipboard-excel
' Declarations -- above and outside of any procedure
Public Declare Function EnumClipboardFormats Lib "user32" ( _
ByVal wFormat As Long) As Long
Public Declare Function OpenClipboard Lib "user32" ( _
ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Declare Function GetClipboardFormatName Lib "user32" _
Alias "GetClipboardFormatNameA" ( _
ByVal wFormat As Long, ByVal lpString As String, _
ByVal nMaxCount As Long) As Long
Public Declare Function IsClipboardFormatAvailable Lib "user32" ( _
ByVal wFormat As Long) As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Sub TestForText()
Dim R As Range
Dim DataObj As MSForms.DataObject
Dim L As Long
Const CF_TEXT As Long = 1&
Set R = Range("A1")
Set DataObj = New MSForms.DataObject
L = IsClipboardFormatAvailable(CF_TEXT)
If L <> 0 Then
' text is available
DataObj.GetFromClipboard
R.Value = DataObj.GetText
Else
Debug.Print "text not available"
End If
End Sub
I pasted the above code into a module but when I run it I get this
error message:
User-defined type not defined on the Dim DataObj As MSForms.DataObject
statement
I'm not sure I handled the declarations correct, "above and outside of
any procedure", the code posted hee is exactly what I copied from the
module.
Any suggestions on how I can get the text pulled from the clipboard?
Thanks
John Keith
(e-mail address removed)