我需要将多个工作表保存为单个文档。我有一个代码,但棘手的部分是只保存值(excel包含公式)。每个工作表都有不同的名称,这些名称将成为单独的Excel的名称。 我该如何调整代码?请帮忙。谢谢!
代码是:
Sub Make_New_Books()
Dim w As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each w In ActiveWorkbook.Worksheets
w.Copy
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path &
"\Requests_for_local_suppliers_to_send\" & w.Name
ActiveWorkbook.Close
Next w
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
这是对现有代码的相当简单的编辑。在w.Copy
命令之后,我们只是选择"所有内容"使用UsedRange
,然后仅在原始数据的顶部复制和粘贴值。
.Copy
创建一个新工作表,因此父工作表中的公式不受此操作的影响。
Sub Make_New_Books()
Dim w As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each w In ActiveWorkbook.Worksheets
w.Copy
ActiveSheet.UsedRange.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path &
"\Requests_for_local_suppliers_to_send\" & w.Name
ActiveWorkbook.Close
Next w
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub