excelmacros将一个文件夹复制到另一个文件夹,用户input的文件夹名称
我试图通过Excelmacros将一个完整的文件夹复制到一个新的文件夹,但我需要用户每次input新的文件夹名称
这是我现在的代码复制到永久/静态文件夹
Sub Copy_Folder() Dim FSO As Object Dim FromPath As String Dim ToPath As String FromPath = "C:\Users\hayekn\Desktop\AR Reports\0MENACA Working File\AR Working File\3- FINAL Country Files\1" '<< Change ToPath = "C:\Users\hayekn\Desktop\AR Reports\0MENACA Working File\AR Working File\Weekly Back" '<< Change Application.CutCopyMode = False If Right(FromPath, 1) = "\" Then FromPath = Left(FromPath, Len(FromPath) - 1) End If If Right(ToPath, 1) = "\" Then ToPath = Left(ToPath, Len(ToPath) - 1) End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " doesn't exist" Exit Sub End If FSO.CopyFolder Source:=FromPath, Destination:=ToPath MsgBox "You can find the files and subfolders from " & FromPath & " in " & ToPath End Sub
我为用户input一个文件夹名称的方法,但无法将此名称链接到正在创build的新文件夹
Dim strName As String Dim WeekStr1 As String Dim WeekStr2 As String Reenter: strName = InputBox(Prompt:="Enter the week you would like to update", _ Title:="Week Selection.", Default:="0") If strName = vbNullString Then Exit Sub Else Select Case strName Case Else MsgBox "Incorrect Entry." GoTo Reenter End Select End If
我需要将“StrName”放置在下面的上下文中,但它似乎无法获得正确的语法
ToPath = "C:\Users\hayekn\Desktop\AR Reports\0MENACA Working File\AR Working File\Week "StrName"" '<< Change
也许像下面?
ToPath = "C:\Users\hayekn\Desktop\AR Reports\0MENACA Working File\AR Working File\Week" & StrName
连接文本/string只需使用&
(&符号)。 +
(加)也可以,但我很满意&
谢谢,我想通过这个问题:)基本上我不得不添加StrName
FSO.CopyFolder Source:= FromPath,Destination:= ToPath&strName
有时最简单的问题是最糟糕的。 谢谢你的帮助
下面是最后的代码供将来参考,以防其他人陷入困境
Sub Copy_Folder() Dim FSO As Object Dim FromPath As String Dim ToPath As String Dim strName As String Dim WeekStr1 As String Dim WeekStr2 As String FromPath = "C:\Users\hayekn\Desktop\AR Reports\0MENACA Working File\AR Working File\3- FINAL Country Files\KSA" '<< Change ToPath = "C:\Users\hayekn\Desktop\AR Reports\0MENACA Working File\AR Working File\Week" Application.CutCopyMode = False Reenter: strName = InputBox(Prompt:="Enter the week you would like to update", _ Title:="Week Selection.", Default:="0") If strName = vbNullString Then MsgBox "Incorrect Entry." GoTo Reenter End If If Right(FromPath, 1) = "\" Then FromPath = Left(FromPath, Len(FromPath) - 1) End If If Right(ToPath, 1) = "\" Then ToPath = Left(ToPath & strName, Len(ToPath) - 1) End If Set FSO = CreateObject("scripting.filesystemobject") If FSO.FolderExists(FromPath) = False Then MsgBox FromPath & " doesn't exist" Exit Sub End If FSO.CopyFolder Source:=FromPath, Destination:=ToPath & strName MsgBox "You can find the files and subfolders from " & FromPath & " in " & ToPath & strName
- 如何创build一个macros将数据从一个Excel工作表复制到另一个工作表中的下一行
- 如何将列A中的特定字符replace为Excel中列B中的值?
- Excel VBA将XL-2007已启用macros的工作簿复制为不带macros的excel-2003文件
- 如何格式化剪贴板中的行和列来粘贴就像来自Excel?
- selection.copy导致selection.pastespecial不工作。 优秀的VBA
- 从Excel电子表格中删除包含重复数据的行?
- Excel VBA如何使用vlookup或替代方法获得dyanmic值
- 将excel(2007)工作表复制到新的工作簿,而不需要引用原始工作簿的公式
- 将工作表复制到其他工作簿,请参阅指向新的工作簿