D
David Hao
The following codes include a module and a class. When I run the module, the
Wb_beforesave event is activated and executed. However, the line with
"Sheets.add" is proceeded but a new sheet is not added as expected. Any guru
knows why this happens and how to solve the problem? For certain reason, I
can not move the "sheets.add" line to the test module before
"activeworkbook.save". I just want to know why my codes do not work in the
way it should work. I have posted in severl excel forums but seems no one
could answer. Thanks!
David
Module
Dim X As New Class1
Sub test()
Set X.App = Application
Set X.Wb = ActiveWorkbook
ActiveWorkbook.Save
End Sub
Class Name: Class1
Public WithEvents App As Application
Public WithEvents Wb As Workbook
Private Sub Wb_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
ActiveWorkbook.Sheets.Add after:=Worksheets(ActiveWorkbook.Worksheets.Count)
End Sub
Wb_beforesave event is activated and executed. However, the line with
"Sheets.add" is proceeded but a new sheet is not added as expected. Any guru
knows why this happens and how to solve the problem? For certain reason, I
can not move the "sheets.add" line to the test module before
"activeworkbook.save". I just want to know why my codes do not work in the
way it should work. I have posted in severl excel forums but seems no one
could answer. Thanks!
David
Module
Dim X As New Class1
Sub test()
Set X.App = Application
Set X.Wb = ActiveWorkbook
ActiveWorkbook.Save
End Sub
Class Name: Class1
Public WithEvents App As Application
Public WithEvents Wb As Workbook
Private Sub Wb_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
ActiveWorkbook.Sheets.Add after:=Worksheets(ActiveWorkbook.Worksheets.Count)
End Sub