Я создал код для перетаскивания файла в форму Excel vba и сохранения его в определенном месте и в SQL.
Но я могу только перетащить из проводника.
Я также хочу перетаскивать файлы из других приложений, таких как Outlook или Whatsapp Web.
Option Explicit
Public DRAGGEDdict As New Dictionary
Private Sub LvDropImageHere_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
Dim FilePAth
Dim fileName As String
Dim FileCol As DataObjectFiles: Set FileCol = Data.Files
Dim orderIdStr As String: orderIdStr = VBA.Trim(Me.orderid.Text)
Dim NewFileName As String: NewFileName = vbNullString
For Each FilePAth In FileCol
NewFileName = GetNewFileName(VBA.CStr(FilePAth), orderIdStr)
If UploadFileOnDrop(VBA.CStr(FilePAth), NewFileName) = True Then
Call UpdateToDBfor_UploadFileOnDrop(NewFileName, orderIdStr)
Call AddListItem(VBA.CStr(NewFileName))
Else
MsgBox "upload to file is failed !", vbCritical
End If
Next
End Sub
Public Function UploadFileOnDrop(FilePAth As String, RemotePAth As String) As Boolean
On Error GoTo exhandler
Dim fSO As New Scripting.FileSystemObject
Call fSO.CopyFile(FilePAth, RemotePAth, True)
UploadFileOnDrop = True
GoTo endsub
exhandler:
UploadFileOnDrop = False
endsub:
End Function