VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Drag and drop Multiple drawing files from multiple folders

7 REPLIES 7
Reply
Message 1 of 8
Jedimaster
2002 Views, 7 Replies

Drag and drop Multiple drawing files from multiple folders

I can browse to a folder and select multiple drawing files in VBA. I need to ablity to drag and drop drawing files from a windows search, perhaps to a listbox of somekind. Basically I need to get need paths and names of selected drawing files to sub routine that opens and pocesses each file.

 

Thanks in advance for any sort of help.

7 REPLIES 7
Message 2 of 8
Hallex
in reply to: Jedimaster

Found this code on forum, try extend it to your suit,

tested in A2007 only:

'Attribute VB_Name = "modFileDialogTest"
Option Explicit
Public Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenFileName As OPENFILENAME) As Long
Public Const OFN_ALLOWMULTISELECT = &H200&
Public Const OFN_EXPLORER = &H80000
Public Const OFN_FILEMUSTEXIST = &H1000&
Public Const OFN_HIDEREADONLY = &H4&
Public Const OFN_PATHMUSTEXIST = &H800&

Sub SelectManyFiles()
Dim FileList As New Collection
Dim I As Long
Dim S As String
ShowFileOpenDialog FileList
With FileList
If .Count > 0 Then
S = "The following files were selected:" + vbCrLf
For I = 1 To .Count
S = S + .Item(I) + vbCrLf
Next
MsgBox S
Else
MsgBox "No files were selected!"
End If
End With
End Sub

Sub ShowFileOpenDialog(ByRef FileList As Collection)
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim FileDir As String
Dim FilePos As Long
Dim PrevFilePos As Long
With OpenFile
.lStructSize = Len(OpenFile)
.hwndOwner = 0
.hInstance = 0
.lpstrFilter = "AutoCad Drawings" + Chr(0) + "*.dwg;*.dxf;" + _
Chr(0) + "All Files (*.*)" + Chr(0) + "*.*" + Chr(0) + Chr(0)
.nFilterIndex = 1
.lpstrFile = String(4096, 0)
.nMaxFile = Len(.lpstrFile) - 1
.lpstrFileTitle = .lpstrFile
.nMaxFileTitle = .nMaxFile
.lpstrInitialDir = "C:\"
.lpstrTitle = "Multi Select Drawings"
.flags = OFN_HIDEREADONLY + _
OFN_PATHMUSTEXIST + _
OFN_FILEMUSTEXIST + _
OFN_ALLOWMULTISELECT + _
OFN_EXPLORER
lReturn = GetOpenFileName(OpenFile)
If lReturn <> 0 Then
FilePos = InStr(1, .lpstrFile, Chr(0))
If Mid(.lpstrFile, FilePos + 1, 1) = Chr(0) Then
FileList.Add .lpstrFile
Else
FileDir = Mid(.lpstrFile, 1, FilePos - 1)
Do While True
PrevFilePos = FilePos
FilePos = InStr(PrevFilePos + 1, .lpstrFile, Chr(0))
If FilePos - PrevFilePos > 1 Then
FileList.Add FileDir + "\" + _
Mid(.lpstrFile, PrevFilePos + 1, _
FilePos - PrevFilePos - 1)
Else
Exit Do
End If
Loop
End If
End If
End With
End Sub

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 8
Jedimaster
in reply to: Jedimaster

This is similar to what I have now. This lets you select multiple files from one folder, it does not allow you to drag them. I am pulling drawings from subfolders. They all have the same drawing name so they cannot reside in one folder.

Message 4 of 8
paulritter
in reply to: Jedimaster

you will need to set the drag and drop for the listbox,

this allows drawing from explorer to a listbox

 

Private Sub List1_OLEDragDrop(Data as DataObject, Effect as Long, Button as Integer, Shift as Integer, X as Single, Y as Single)

  Dim numFiles as Integer

    numFiles = Data.Files.Count
  Dim sFileNamePath as String
  Dim sExt as String
    MsgBox numFiles
  Dim i as Integer
    For i = 1 To numFiles
        sFileNamePath = Data.Files(i)
        sExt = Right(sFileNamePath, 4)
        sExt = UCase(sExt)
        If (GetAttr(sFileNamePath) And vbDirectory) <> vbDirectory And sExt = ".DWG" Then
            List1.AddItem sFileNamePath & " | " & GetAttr(sFileNamePath)
        End If
    Next i

End Sub

 

Message 5 of 8
Jedimaster
in reply to: paulritter

Thank you for the response. I have never used OLEDragDrop, is this standard AutoCAD VBA or do I need to install Additional Control, ocx or add-in?

Message 6 of 8
paulritter
in reply to: Jedimaster

well i thought i understood what you meant..

you wanted to drag files from windows explorer to a vb form?

if that is correct lookup OLEDragDrop it is part of form controls.. textbox, listbox, listview, treeview...etc

if that is not what you meant... nevermind...lol

Message 7 of 8
Jedimaster
in reply to: paulritter

I think you understood what I was asking for. I have never used OLEDragDrop to add files to a list box. I am using the AutoCAD VBA interface so it is a bit limited. What I am attempting to achieve over all is to take Windows search for all dwg files in a Project folder and sub folders. Drag and drop the file names and paths to a VBA form listbox or something similar. Then take the list and open and process each file. I think what you gave me is what I am looking for. I made a userform with a list box named List1 I attached the code and tested it. When I drag the files to the list box it gives me the circle with a slash through it. Is this a function that could possibly be excusive to VB instead of VBA?

Message 8 of 8
Jedimaster
in reply to: Hallex

On another note with using comdlg32.dll to open multiple files I have hit a limit of 255 files. Is there a way around this?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost