我编写了一个宏,它可以使用命令shell组合所选文件夹中的文件。我使用命令提示符的原因是文件很大并且需要一些时间才能打开。
问题是,当我选择包含空格的文件夹(即J:\ Network Accrual \ Invoices)时,宏会失败。我试图遵循其他建议,包括4个引语(""""& path&"""&# 34;),但这似乎不适用于我设置的操作 - " cmd.exe / C copy J:\ TEST * csv J:\ TEST \ Combined.csv"。
以下是代码:
Private Sub COMBINE_FILES()
Dim FldrPicker As FileDialog
Dim myPath As String
'Retrieve Target Folder Path From User
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With
'In Case of Cancel
NextCode:
myPath = myPath
If myPath = "" Then GoTo ResetSettings
'Display path
MsgBox myPath
'Combine files in Command Line
Dim RET As Variant
RET = Shell("cmd.exe /C copy " & myPath & "*csv " & myPath & "Combine.csv", 0)
ResetSettings:
'Reset Macro Optimization Settings
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
尝试
RET = Shell("cmd.exe /C copy """ & myPath & "*csv"" """ & myPath & "Combine.csv""", 0)