Solved

Receive File with Drop

Posted on 1998-10-20
5
143 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

773 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