我真的需要帮助。我需要一个VBA函数来复制单个PDF文件。例如一个带有引用/名称1的文件,我需要一个x的副本,比如1到10.为了避免复制和粘贴9次并手动重命名,我确信必须有一个函数来完成这项工作。我对VBA非常基本,所以任何帮助都会非常感激。
非常感谢
答案 0 :(得分:0)
首先,您需要在VBA编辑器中添加对Microsoft Scripting Runtime的引用。然后以下内容将起作用......
Public Sub Test()
CopyFile "C:\Users\randrews\Desktop\1.gif", "C:\Users\randrews\Desktop", 10
End Sub
Public Sub CopyFile(OriginalPath As String, DestinationFolderPath, Copies As Integer)
Dim fs As New FileSystemObject
For i = 1 To Copies
OrigName = fs.GetFileName(OriginalPath) 'file name with extention e.g. 1.gif
OrigNumber = CInt(Left(OrigName, Len(OrigName) - 4)) 'file name converted to a number - this will crash if the file name contains any non numeric chars
DestName = OrigNumber + i & "." & fs.GetExtensionName(OriginalPath) 'new file name = original number + i + the file extension
fs.CopyFile OriginalPath, DestinationFolderPath & "\" & DestName
Next i
End Sub