Drag and drop text in userform text / combo boxes

R

Roger on Excel

I am using userforms alot for data entry.

Is there a way to allow one to drag and drop text from one text box / combo
box to another?

This would be especially useful since it would allow me to move entered data
down or up within the userform during editing. However i cannot drag text
from one box to another (as one can in say word or in the sheet itself).

Can anyone help?
 
P

Peter T

This is very basic just to get you started. There's a lot more you will
probably want to do, also slightly different approaches -

'' put some text in Textbox1
'' press left button and hold Ctrl with mouse over Textbox1
'' drag and release over Textbox2


Private msText As String

Private Sub TextBox1_BeforeDragOver( _
ByVal Cancel As MSForms.ReturnBoolean, _
ByVal Data As MSForms.DataObject, _
ByVal X As Single, ByVal Y As Single, _
ByVal DragState As MSForms.fmDragState, _
ByVal Effect As MSForms.ReturnEffect, ByVal Shift As
Integer)
Cancel = True
End Sub

Private Sub TextBox1_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As
Single)

If Button = 1 And Shift = 2 Then
Set dataObj = New MSForms.DataObject
msText = TextBox1.Text
dataObj.StartDrag
End If
End Sub


Private Sub TextBox1_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

msText = ""

End Sub

Private Sub TextBox2_BeforeDragOver( _
ByVal Cancel As MSForms.ReturnBoolean, _
ByVal Data As MSForms.DataObject, _
ByVal X As Single, ByVal Y As Single, _
ByVal DragState As MSForms.fmDragState, _
ByVal Effect As MSForms.ReturnEffect, _
ByVal Shift As Integer)

Cancel = True
End Sub

Private Sub TextBox2_BeforeDropOrPaste( _
ByVal Cancel As MSForms.ReturnBoolean, _
ByVal Action As MSForms.fmAction, _
ByVal Data As MSForms.DataObject, _
ByVal X As Single, ByVal Y As Single, _
ByVal Effect As MSForms.ReturnEffect, _
ByVal Shift As Integer)

TextBox2.Text = msText

End Sub

Regards,
Peter T
 

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