Thread: Save Macro
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Save Macro

Use the before save event for the thisworkbook object/module

http://www.cpearson.com/excel/events.htm

Private Sub Workbook_BeforeSave( _
ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim sh as Worksheet
ThisWorkbook.Activate
for each sh in thisworkbook.Worksheets
sh.Activate
sh.Range("A1").Select
Next
thisworkbook.worksheets(1).Select
Cancel = True
On Error goto ErrHandler
Application.EnableEvents = False
ThisWorkbook.Save
ErrHandler:
Application.EnableEvents = True
End Sub

This must be in the ThisWorkbook Module.

--
Regards,
Tom Ogilvy

"Sprinks" wrote in message
...
I'd like a macro that, prior to saving the current workbook, would

position
the cursor in cell A1, and make the first sheet the active one. The
following code does not work. Can anyone help?

Public Sub SaveWorksheet()
Dim wrksht As Worksheet
For Each wrksht In ActiveWorkbook.Worksheets
Range("A1").Select
Next wrksht
Worksheets(1).Select
ActiveWorkbook.Save
End Sub

Sprinks