简体   繁体   English

excel vba 使用列表框移动多个文件

[英]excel vba move multiple files using listbox

I have created a form with three list boxes.我创建了一个包含三个列表框的表单。 The first loads with the files in a selected folder.第一个加载选定文件夹中的文件。 I then select several files in the first list and move them into the second list box.然后我在第一个列表中选择几个文件并将它们移动到第二个列表框中。 The files in the second list box now need to be copied into folders listed in the third list box.现在需要将第二个列表框中的文件复制到第三个列表框中列出的文件夹中。 All the issues of setting the source and destination paths are done.设置源路径和目标路径的所有问题都已完成。 I need the lines of code which cause the selected files in the second list to be copied to the selected destination in the third list box.我需要将第二个列表中的选定文件复制到第三个列表框中的选定目标的代码行。

Sample code:示例代码:

FileToCopy = FileSourceDirectory & lstSelectedFiles.Value
DestinationFolderName = UserRepositoryDirectory & lstRepositoryFolders
CopiedFile = DestinationFolderName & "\" & lstSelectedFiles.Value
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
FileCopy FileToCopy, CopiedFile Unload frmCopyFileToRepository
Dim i As Integer
 For i = 0 To lstSelectedFiles.ListCount - 1

  FileToCopy = FileSourceDirectory & lstSelectedFiles.List(i)

      CopiedFile = DestinationFolderName & "\" & lstSelectedFiles.List(i)

  Set fso = VBA.CreateObject("Scripting.FileSystemObject")

FileCopy FileToCopy, CopiedFile

Next i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM