Solved

Receive File with Drop

Posted on 1998-10-20
5
140 Views
Last Modified: 2011-10-03
I want to have a form on to which the user can drag a file.  I want the drop to be an event, so that I can process the file as necessary.  How do I report the path to the file to a variable, and which event should I use to execute my code?
0
Comment
Question by:IsleOfView
5 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1440793
Set OleDropMode to Automatic.
Now you will receive an event.
0
 
LVL 5

Expert Comment

by:AnswerTheMan
ID: 1440794
Mirkwood : i've a feeling u got him all wrong.
IsleOfView: what exactly do u mean : "Dragging a file" ?
0
 

Author Comment

by:IsleOfView
ID: 1440795
I want to be able to drag a file from Windows Explorer, Desktop or whatever, get the filename into a variable, and execute code from there.  I know that the OleDrop mode will give me an event, but how do I get the filename? (i.e. "c:\testing\mytext.txt")
0
 
LVL 15

Accepted Solution

by:
ameba earned 50 total points
ID: 1440796
Set OleDropMode property of your Form to Manual.

' use its OLEDragDrop event
Private Sub Form1_OLEDragDrop(Data As DataObject, Effect ...)
    Call OLEDragDrop(Data)
End Sub

Public Sub OLEDragDrop(Data As DataObject)
    Dim i%, numfile%, filetxt$, filnam As String
    If Data.GetFormat(vbCFFiles) Then
        On Error GoTo NEXTFILE
        For i = 1 To Data.Files.Count
            filnam = CStr(Data.Files.Item(i))
            numfile% = FreeFile
            Open filnam For Input As #numfile%
            'read file and do something, e.g. show first line
            Line Input #numfile%, filetxt$
            MsgBox filnam & vbCrLf & filetxt$
            Close numfile%
NEXTFILE:
        Next
    End If
End Sub
0
 

Author Comment

by:IsleOfView
ID: 1440797
Thank you...that worked perfectly.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

758 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

19 Experts available now in Live!

Get 1:1 Help Now