我在我的工作表中使用以下代码:
Sub savesheet2()
Application.ScreenUpdating = False
ActiveSheet.Select
ActiveSheet.Copy
ThisFile = Range("A1").Text
Dim fileName As String
fileName = "H:\PUS\Overhead\Planning&Control\Planning\Leveranciers core\bestellingen\" & ThisFile
ActiveSheet.SaveAs fileName:=fileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Application.ScreenUpdating = True
End Sub
我希望的是,对于新保存的工作簿,所有公式都保存为值,因此单元格中没有可见的公式。
我希望有一个人可以帮助我?
提前致谢!
答案1
之后:
ActiveSheet.Copy
包括:
Cells.Copy
Cells.PasteSpecial xlPasteValues
答案2
您可以尝试这个简单的 VBA 代码将所有公式转换为值并保存工作簿。
Sub Saveasvalue()
Dim wsh As Worksheet
For Each wsh In ThisWorkbook.Worksheets
wsh.Cells.Copy
wsh.Cells.PasteSpecial xlPasteValues
Next
Application.CutCopyMode = False
Application.ActiveWorkbook.SaveAs Filename:="YOUR PATH\" & YOURWorkbookName, FileFormat:= xlNormal, CreateBackup:=False
End Sub
或者也可以这样用,
Dim wsh As Worksheet
For Each wsh In ActiveWorkbook.Sheets
wsh.UsedRange.Value = wsh.UsedRange.Value
Next
ThisWorkbook.Save