①打开指定位置的工作薄
Dim fname As String
fname = "D:\测试.xls"
Workbooks.Open Filename:=fname, ReadOnly:=True '以只读方式打开
②保存工作薄
ActiveWorkbook.Save
③保存每个工作薄并退出Excel
For Each wb In Application.Workbooks
wb.Save
Next wb
Application.Quit
④另存工作薄的多种方法
第一种方法:ActiveWorkbook.SaveAs "<工作簿名>.xls"
第二种方法:
Dim oldName As String, newName As String
Dim folderName As String, fname As String
oldName = ActiveWorkbook.Name
newName = "new" & oldName
MsgBox "将<" & oldName & ">以<" & newName & ">的名称保存"
folderName = Application.DefaultFilePath
fname = folderName & "\" & newName
ActiveWorkbook.SaveAs fname
End Sub
示例说明:本示例将当前工作簿以一个新名(即new加原名)保存在默认文件夹中。
第三种方法
ActiveWorkbook.SaveAs CreateBackup:=True '本示例将在当前文件夹中建立工作簿的备份