I have found a way to achieve this. As far as I can tell, this can only be done using the treeview control. You may need to right-click on the toolbar to find and add it. He will be there under “additional control” or something like that. You will need two things besides control.
In the UserForm_Initialize routine, you need the following line of code to enable drag and drop: TreeView1.OLEDropMode = ccOLEDropManual :
UserForm_Initialize() TreeView1.OLEDropMode = ccOLEDropManual End Sub
Then you will need the Private Sub TreeView1_OLEDragDrop event. I omitted all options to save space. They should be easy enough to find. In this routine, just declare a line, maybe strPath or something like that, to save the file name and path, and set strPath = Data.Files(1) and this will get the file name and path to the file that the user drags into Treeview the control. This assumes that the user only drags one file at a time, but as far as I can tell, this should be something that can be done by dragging and dropping several files if you experiment with it.
Private Sub TreeView1_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single) StrPath = Data.Files(1) End Sub
Change: You will also need to add a link to Microsoft Windows Common Controls 6.0
I also added sample code.
Mattb
source share