Solved

Receive File with Drop

Posted on 1998-10-20
5
146 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no 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.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

751 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