我想创建一个新的工作簿,在其中添加一个列表,然后保存这本书。如果存在,我需要删除以前的变体,然后保存当前。这是我的代码:
Private Sub GenerateReport_Click()
Dim wb As Workbook
Dim FilePath As String
FilePath = ThisWorkbook.Path + "\CommonReport.xls"
Set wb = Workbooks.Add
ActiveCell.FormulaR1C1 = "a1"
wb.ActiveSheet.Range("B1").Select
ActiveCell.FormulaR1C1 = "b1b"
wb.ActiveSheet.Range("C1").Select
ActiveCell.FormulaR1C1 = "3"
wb.ActiveSheet.Range("D1").Select
ActiveCell.FormulaR1C1 = "4"
wb.ActiveSheet.Range("E1").Select
ActiveCell.FormulaR1C1 = "5"
wb.ActiveSheet.Range("F1").Select
ActiveCell.FormulaR1C1 = "6"
wb.ActiveSheet.Range("G1").Select
ActiveCell.FormulaR1C1 = "7"
wb.ActiveSheet.Range("A1:G1").Select
wb.ActiveSheet.ListObjects.Add(xlSrcRange, wb.ActiveSheet.Range("$A$1:$G$1"), , xlYes).Name = "Ñïèñîê1"
wb.ActiveSheet.Range("A1:G2").Select
Application.DisplayAlerts = False
If Dir(FilePath) = vbNullString Then
wb.SaveAs Filename:=FilePath
Else
SetAttr FilePath, vbNormal
Kill FilePath
End If
End Sub
书籍打开时是否可以删除。当我想删除已打开的书时,如何处理错误?