VB6 drag and drop: grab file name and path into textbox

Posted on 2010-01-04
Last Modified: 2012-05-08
Dear Experts,

I would like to drag and drop a file/folder from Windows Explorer into a standard textbox, and have the file name and path appear.  I am using manual drag and drop.  So I guess I need a way of converting Data.GetData(vbCFFiles) into text format. The Str() function does not work.

Question by:ttobin333
    LVL 85

    Accepted Solution

    Try something like:
    Option Explicit
    Private Sub Form_Load()
        Text1.OLEDropMode = 1 ' Manual
    End Sub
    Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Data.GetFormat(vbCFFiles) Then
            Dim sText As String
            Dim i As Integer
            For i = 1 To Data.Files.Count
                sText = sText & Data.Files(i) & vbCrLf
            Text1.SelText = sText
        End If
    End Sub

    Open in new window


    Author Closing Comment

    Perfect! Thanks Idle_Mind!

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now