Saving

  • Thread starter Thread starter eman
  • Start date Start date
E

eman

I have a small program called 'Notebook' that when I close it, it saves
automatically without selecting File/Save as. Is it possible to make this in
Excel? I mean closing Excel without selecting save as each time but it saves
automatically on closing!
 
Put this in Personal.xls


Public WithEvents App As Application

Private Sub App_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean)
Wb.Save
End Sub

Private Sub Workbook_Open()
Set App = Application
End Sub


'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
If workbook window is maximized the Excel Icon will be left of "File" on the
menubar.

If not maximized, will be at left end of title bar.


Gord Dibben MS Excel MVP
 
Uh, the Excel icon?

It is the Excel image at the top left of the worksheet next to the worksheet
name.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
I can't see any 'View Code' in that menu! What I can see is: new, open,
convert, save, save as, print, prepare, send, publish and close!
 
Maybe you're using version 2007?

Just right click the sheet tab and select View Code, then double click
ThisWorkbook, and paste the code there-in.

Rob
 
Yes I am using 2007.

I pasted the code but still it isn't saving, it is still asking me if I want
to save as before!

When pasting the code do I have to save or something?
 
Did you paste this whole section? (Make sure there are no line
breaks....that is, don't have any red lines showing once pasted!). If you do
have some red lines, it is best to maximise this window before you copy the
code.

Public WithEvents App As Application

Private Sub App_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean)
Wb.Save
End Sub

Private Sub Workbook_Open()
Set App = Application
End Sub

It works fine when I tried it. Maybe you didn't save the work book first as
an .xlsm file (ie macro enabled)?

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top