将特定工作表保存在文件夹中

时间:2017-08-28 11:57:21

标签: excel vba excel-vba

我正在尝试将特定工作表保存在名为" DD"的文件夹中。

我运行了以下代码。它将工作表和存储保存在路径中,但不保存在特定文件夹中。

任何人都可以帮助我做到这一点。

Sub save()

Dim myWorksheets() As String
Dim newWB As Workbook
Dim CurrWB As Workbook
Dim i As Integer
Dim path1, Path2 As String
path1 = ThisWorkbook.Path
Path2 = path1 & "\DD"
Set CurrWB = ThisWorkbook
myWorksheets = Split("Report", ",")
For i = LBound(myWorksheets) To UBound(myWorksheets)
    Set newWB = Workbooks.Add
    CurrWB.Sheets(Trim(myWorksheets(i))).Copy Before:=newWB.Sheets(1)
    newWB.SaveAs filename:=Path2 & Format(Now(), "yyyymmdd") & myWorksheets(i) & ".xlsx"
    newWB.Close SaveChanges:=True
Next i

End Sub

1 个答案:

答案 0 :(得分:2)

你忘记了反斜杠:

Path2 = path1 & "\DD\"