Maybe :
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type DROPFILES
pFiles As Long
pt As POINTAPI
fNC As Long
fWide As Long
End Type
Private Const CF_HDROP = 15
Private Const GMEM_MOVEABLE = &H2
Private Const GMEM_ZEROINIT = &H40
Private Const GHND = (GMEM_MOVEABLE Or GMEM_ZEROINIT)
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function DragQueryFile Lib "shell32.dll" Alias "DragQueryFileA" (ByVal hDrop As Long, ByVal UINT As Long, ByVal lpStr As String, ByVal ch As Long) As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Function GetFilesFromClipboard(strFiles() As String) As Long
Const MAX_PATH As Long = 260
Dim pt As POINTAPI, hDrop As Long, nFiles As Long, nNul As Long, i As Long, desc As String, strFilename As String
If IsClipboardFormatAvailable(CF_HDROP) Then
If OpenClipboard(0&) Then
hDrop = GetClipboardData(CF_HDROP)
nFiles = DragQueryFile(hDrop, -1&, "", 0)
ReDim strFiles(1 To nFiles) As String
strFilename = Space$(MAX_PATH)
For i = 1 To nFiles
Call DragQueryFile(hDrop, i - 1, strFilename, Len(strFilename))
nNul = InStr(strFilename, vbNullChar)
Select Case nNul
Case Is > 1: strFiles(i) = Left$(strFilename, nNul - 1)
Case 1: strFiles(i) = ""
Case 0: strFiles(i) = Trim$(strFiles(i) = "")
End Select
Next
Call CloseClipboard
End If
GetFilesFromClipboard = nFiles
End If
End Function
Public Function SetFilesToClipboard(strFiles() As String) As Boolean
Dim df As DROPFILES, hGlobal As Long, lpGlobal As Long, i As Long, strData As String
If OpenClipboard(0&) Then
EmptyClipboard
For i = LBound(strFiles) To UBound(strFiles)
strData = strData & strFiles(i) & vbNullChar
Next
strData = strData & vbNullChar
hGlobal = GlobalAlloc(GHND, Len(df) + Len(strData))
If hGlobal Then
lpGlobal = GlobalLock(hGlobal)
df.pFiles = Len(df)
CopyMem ByVal lpGlobal, df, Len(df)
CopyMem ByVal (lpGlobal + Len(df)), ByVal strData, Len(strData)
GlobalUnlock hGlobal
If SetClipboardData(CF_HDROP, hGlobal) Then SetFilesToClipboard = True
End If
CloseClipboard
End If
End Function
Sample usage :
Sub Test_GetFilesFromClipboard()
Dim strFile() As String, i As Long, v
i = GetFilesFromClipboard(strFile)
If i > 0 Then
For Each v In strFile
Debug.Print v
Next v
End If
End Sub
Sub Test_SetFilesToClipboard()
Dim strFile(1 To 2) As String
strFile(1) = "Z:\1.txt"
strFile(2) = "Z:\2.txt"
If SetFilesToClipboard(strFile) Then Debug.Print "Success" Else Debug.Print "Failed"
End Sub
Sub Test_EF1166264()
Dim strPattern As String, strPath As String, strFile() As String, i As Long, vFile
strPattern = "Z:\*.*" 'Change this to something like strPattern = "S:\PDF_Jobs\" & ComboBox1 & "\" & ComboBox2 & "\" & ComboBox3 & "\*.*"
strPath = Left$(strPattern, InStrRev(strPattern, "\"))
ReDim strFile(1 To 1000) As String
vFile = Dir(strPattern)
While vFile <> ""
i = i + 1
strFile(i) = strPath & vFile
vFile = Dir
Wend
If i > 0 Then ReDim Preserve strFile(1 To i) As String
For i = 1 To UBound(strFile): Debug.Print strFile(i): Next i
If i > 0 Then SetFilesToClipboard strFile
End Sub
Bookmarks