gpt4 book ai didi

vba - 使用 VBA 宏将每个 Excel 工作表另存为单独的工作簿

转载 作者:行者123 更新时间:2023-12-01 06:36:05 25 4
gpt4 key购买 nike

您好我正在尝试使用此代码将每张 Excel 表保存到新工作簿中。但是,它将整个工作簿保存为新文件名

Dim path As String
Dim dt As String
dt = Now()
path = CreateObject("WScript.Shell").specialfolders("Desktop") & "\Calendars " & Replace(Replace(dt, ":", "."), "/", ".")
MkDir path
Call Shell("explorer.exe" & " " & path, vbNormalFocus)

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets 'SetVersions
If ws.name <> "How-To" And ws.name <> "Actg_Prd" Then
ws.SaveAs path & ws.name, xlsx
End If
Next ws

什么是快速修复?

最佳答案

将工作表保留在现有工作簿中并创建带有副本的新工作簿

Dim path As String
Dim dt As String
dt = Now()
path = CreateObject("WScript.Shell").specialfolders("Desktop") & "\Calendars " & Replace(Replace(dt, ":", "."), "/", ".")
MkDir path
Call Shell("explorer.exe" & " " & path, vbNormalFocus)

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets 'SetVersions
If ws.Name <> "How-To" And ws.Name <> "Actg_Prd" Then
Dim wb As Workbook
Set wb = ws.Application.Workbooks.Add
ws.Copy Before:=wb.Sheets(1)
wb.SaveAs path & ws.Name, Excel.XlFileFormat.xlOpenXMLWorkbook
Set wb = Nothing
End If
Next ws

关于vba - 使用 VBA 宏将每个 Excel 工作表另存为单独的工作簿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19940409/

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