Friday, May 04, 2007

Drag & DRop Files to Text Box

Show File Name in Text Box using Drag & Drop

Private Sub TextBox1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i1 As Integer '* Files Counter

On Error GoTo Err_Trap

If Data.GetFormat(vbCFFiles) = True Then
i1 = Data.Files.Count
If i1 = 1 Then
If InStr(1, LCase$(Data.Files(i1)), ".xls") Then
txtExcel.Text = Data.Files(i1)
End If
End If
End If

' ------------------------------------------
' Error Handling
' ------------------------------------------
Err_Trap:
If Err <> 0 Then
Debug.Assert Err = 0
Err.Clear
End If
End Sub

This will be used to show the file name in the Text Box if a file is dragged and dropped into it

2 comments:

  1. Anonymous6:31 AM

    thanks a lot !

    ReplyDelete
  2. Hi

    I am trying to replicate your code, but I am not able to do so. I have a userform with a textbox named Textbox1, but OLEDragDrop is not one of the events listed for TextBox1. I have copied the code, but dropping a file on the textbox does not trigger the event. the How does one enable the OLE event? I have also tried using the BeforeDropOrPaste event, but to no avail.

    Any help would be great, thanks!

    ReplyDelete

StumbleUpon
Share on Facebook
Related Posts Plugin for WordPress, Blogger...
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.