gpt4 book ai didi

vba - 将excel中的工作表保存到另一个excel

转载 作者:行者123 更新时间:2023-12-04 21:11:34 24 4
gpt4 key购买 nike

我有一个包含多张工作表的工作簿,我想将工作簿中的两张工作表保存到另一个新工作簿中。

我尝试了下面的代码,但它只将我的工作簿中的一张表复制到另一张表中。

谁能告诉我哪里出错了?

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 & "\Saved Files\SW\"
Set CurrWB = ThisWorkbook
myworksheets = Split("BW", "Reason")
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(), "WW") & " CW " & myworksheets(i) & ".xlsx"
newWB.Close SaveChanges:=True
Next i
Application.ScreenUpdating = False
MsgBox ("File Saved")
End Sub

最佳答案

更改此行 myworksheets = Split("BW", "Reason")myworksheets = Split("BW,Reason", ",")

关于vba - 将excel中的工作表保存到另一个excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50600891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com