Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default error trying to use GetFromClipboard

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.as...lipboard-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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default error trying to use GetFromClipboard

Take a look at the notes on Chip Pearson's site:
http://www.cpearson.com/Excel/clipboard.aspx

Especially, the first paragraph where he describes how to set a reference inside
the VBE.



On 06/13/2010 16:19, John Keith wrote:
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.as...lipboard-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


--
Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default error trying to use GetFromClipboard

On Sun, 13 Jun 2010 18:16:50 -0500, Dave Peterson
wrote:

Take a look at the notes on Chip Pearson's site:
http://www.cpearson.com/Excel/clipboard.aspx

Dave,

Thank you for the pointer, but I'm not quite there yet.

I went to the tools menu on the VB editor, selected references and
found a multitude of items that could be selected but no MS Forms 2.0
Object Library. I'll try a internet search but if you have some
suggestions please pass them on.


John Keith

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default error trying to use GetFromClipboard

It should be there, are you looking for
"Microsoft Forms 2.0 Object Library"
it might be near the top of the list rather than in alphabetical order

Simple way to add the reference is to add a userform, which you can remove
immediately.

Keep in mind the DataObject only returns Text, if any, in the clipboard. If
copying from cells and depending on the numberformat that might be different
to the Value property.

FWIW, instead of the clipboard APIs. to check if text is available you can
do simply something like this

Sub test2()
Dim DataObj As MSForms.DataObject

Set DataObj = New MSForms.DataObject
DataObj.GetFromClipboard

If DataObj.GetFormat(1&) Then
Debug.Print DataObj.GetText
Else
Debug.Print "text not available"
End If

End Sub

Regards,
Peter T


"John Keith" wrote in message
...
On Sun, 13 Jun 2010 18:16:50 -0500, Dave Peterson
wrote:

Take a look at the notes on Chip Pearson's site:
http://www.cpearson.com/Excel/clipboard.aspx

Dave,

Thank you for the pointer, but I'm not quite there yet.

I went to the tools menu on the VB editor, selected references and
found a multitude of items that could be selected but no MS Forms 2.0
Object Library. I'll try a internet search but if you have some
suggestions please pass them on.


John Keith


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default error trying to use GetFromClipboard

To use MSFORMS.DATAOBJECT,
You should insert a user-form , once you have inserted a user-form,
you may remove it.
Creating a user-form causes making a referrence to MSFORMS Library.

Or you can use MSFORMS.DATAOBJECT without refferencing the library.
See my site : http://akihitoyamashiro.com/en/VBA/L...DataObject.htm
about that.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Right icw getfromclipboard Basta1980 Excel Programming 2 February 4th 10 11:31 AM
Error handling error # 1004 Run-time error [email protected] Excel Programming 3 May 20th 08 02:23 PM
GetFromClipboard help needed please LuisE Excel Programming 0 December 15th 07 06:54 PM
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Automation Error, Unknown Error. Error value - 440 Neo[_2_] Excel Programming 0 May 29th 04 05:26 AM


All times are GMT +1. The time now is 09:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"