如何基于Excel中的列表将文件从一个文件夹复制或移动到另一个文件夹?

您所在的位置:网站首页 如何将ppt中的表格复制到文件夹里面 如何基于Excel中的列表将文件从一个文件夹复制或移动到另一个文件夹?

如何基于Excel中的列表将文件从一个文件夹复制或移动到另一个文件夹?

2024-07-03 18:50| 来源: 网络整理| 查看: 265

Hello! Can anybody help me to fix this code to use it for copy .pdf files. This code works greate for .png or .jpg files, but doesn't work with pdf.

Sub Copyfiles() 'Updateby Extendoffice Dim xRg As Range, xCell As Range Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog Dim xSPathStr As Variant, xDPathStr As Variant Dim xVal As String Dim fso As Object, folder1 As Object ' On Error Resume Next Set xRg = Application.InputBox("Please select the file names:", "KuTools For Excel", ActiveWindow.RangeSelection.Address, , , , , 8) If xRg Is Nothing Then Exit Sub Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker) xSFileDlg.Title = " Please select the original folder:" If xSFileDlg.Show -1 Then Exit Sub xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\" Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker) xDFileDlg.Title = " Please select the destination folder:" If xDFileDlg.Show -1 Then Exit Sub xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\" Call sCopyFiles(xRg, xSPathStr, xDPathStr) End Sub

Sub sCopyFiles(xRg As Range, xSPathStr As Variant, xDPathStr As Variant) Dim xCell As Range Dim xVal As String Dim xFolder As Object Dim fso As Object Dim xF As Object Dim xStr As String Dim xFS As Object Dim xI As Integer On Error Resume Next If Dir(xDPathStr, vbDirectory) = "" Then MkDir (xDPathStr) End If For xI = 1 To xRg.Count Set xCell = xRg.Item(xI) xVal = xCell.Value If TypeName(xVal) = "String" And Not (xVal = "") Then On Error GoTo E1 If Dir(xSPathStr & xVal, 16) Empty Then FileCopy xSPathStr & xVal, xDPathStr & xVal End If End If E1: Next xI On Error Resume Next Set fso = CreateObject("Scripting.FileSystemObject") Set xFS = fso.GetFolder(xSPathStr) For Each xF In xFS.SubFolders xStr = xDPathStr '& "\" & xF.Name ' Replace(xF.ShortPath, xSPathStr, xDPathStr) Call sCopyFiles(xRg, xF.ShortPath & "\", xStr & "\") If (CreateObject("scripting.FileSystemObject").GetFolder(xStr).Files.Count = 0) _ And (CreateObject("scripting.FileSystemObject").GetFolder(xStr).SubFolders.Count = 0) Then RmDir xStr End If Next End Sub



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3