Any gura can help?

dfhao

New Member
Joined
Aug 13, 2007
Messages
2
I defined a class and a module in my excel workbook. They are as the following:

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

#


The problem is if you click "Save", a new sheet will be added. But if you run the module, the sheets.add line is executed but a new sheet is not added. I need the Activeworkbook.save line to activate the save event, instead of clicking the "Save" button from the menu bar. Any guru knows why and how to solve the problem? Thanks!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
What is it you are actually trying to achieve?
 
Upvote 0
What I would like to do is to relate the above module to a pop up menu bar. When user clicks the menu bar, a message box will popup asking if the user would like to save the workbook before proceeding. If "yes" is clicked, the activateworkbook.save is executed and the beforesave event activated. The beforesave event will add a new sheet and record some coverted information from the existing sheets and then save the workbook. Thanks!

David
 
Upvote 0
David

Perhaps I'm missing something but couldn't you just use the BeforeSave event for that?

Why the class?
 
Upvote 0

Forum statistics

Threads
1,214,576
Messages
6,120,350
Members
448,956
Latest member
Adamsxl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top