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!
 

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows
What is it you are actually trying to achieve?
 

dfhao

New Member
Joined
Aug 13, 2007
Messages
2
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows
David

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

Why the class?
 

Watch MrExcel Video

Forum statistics

Threads
1,123,307
Messages
5,600,869
Members
414,411
Latest member
Snowmanaus

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
Top