VBA: Read file from clipboard

前端 未结 3 2020
悲哀的现实
悲哀的现实 2020-12-10 19:44

I\'m trying to load a file in a VBA macro that has been copied from, say, an Explorer window.

I can easily get the data from the clipboard using DataObject::GetFrom

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 20:31

    Save the files if they are in the clipboard to the destination folder.

    Public Declare PtrSafe Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
    
    Public Const CF_HDROP       As Long = 15
    
            Public Function SaveFilesFromClipboard(DestinationFolder As String) As Boolean
                SaveFilesFromClipboard = False
                If Not CBool(IsClipboardFormatAvailable(CF_HDROP)) Then Exit Function
                CreateObject("Shell.Application").Namespace(CVar(DestinationFolder)).self.InvokeVerb "Paste"
                SaveFilesFromClipboard = True
            End Function
    

提交回复
热议问题