User defined type not defined

B

Blur

I keep getting user defined type not defined when i try to run this...
Which are the neccessary libraries which i have to add in my
references? I have added the Microsoft VB Extensibility but it does not
work.. It always break at
" Set TempDO = New DataObject "

It's supposed to place my 15 randomly selected cells on the
clipboard... how can i modify it to place the results on the worksheet
itself?
Many thanks.....



Code:
--------------------
Sub GetRandom()
Dim iRows As Integer
Dim iCols As Integer
Dim iBegRow As Integer
Dim iBegCol As Integer
Dim J As Integer
Dim sCells As String

Set TempDO = New DataObject

iRows = Selection.Rows.Count
iCols = Selection.Columns.Count
iBegRow = Selection.Row
iBegCol = Selection.Column

If iRows < 16 Or iCols > 1 Then
MsgBox "Too few rows or too many columns"
Else
Randomize Timer
sCells = ""
For J = 1 To 15
iWantRow = Int(Rnd() * iRows) + iBegRow
sCells = sCells & Cells(iWantRow, iBegCol) & vbCrLf
Next J
TempDO.SetText sCells
TempDO.PutInClipboard
End If
End Sub
 
D

Dave Peterson

You'll want to add a reference (Tools|references in the VBE) to:
Microsoft Forms 2.0 Object library

So that your project knows what a Dataobject is.

Also, I'd add one more dim statement:

Dim TempDO As MSForms.DataObject
 

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