#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saving

I have written an macro to save the contents of the excel
sheet into a database whenever the SAVE is clicked in the
standard command bar. If the excel template is a read only
one, when the save is clicked excel gives a message "
Template is read only choose a different name to save"
after "OKying" it performs the macro that i have written.
Is there anyway to suppress that message. I even tried

Application.displayalerts=false but still the message
appears.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 473
Default Saving

Adhavan Veeraiyan wrote:
I have written an macro to save the contents of the excel
sheet into a database whenever the SAVE is clicked in the
standard command bar. If the excel template is a read only
one, when the save is clicked excel gives a message "
Template is read only choose a different name to save"


One approach would be to take over the File / Save menu item and
associated toolbar buttons by assigning your macro to them.

This would need to be done carefully - ensuring that you remove the
assignment when your workbook is not active or is closed.

Something along these lines

Sub MySave()
If ActiveWorkbook.Name = ThisWorkbook.Name Then
MsgBox "MySave"
ElseIf ActiveWorkbook.ReadOnly Or ActiveWorkbook.Path = "" Then
Application.Dialogs(xlDialogSaveAs).Show
Else
ActiveWorkbook.Save
End If
End Sub

Sub GrabSave()
Dim CB As CommandBar
Dim CTL As CommandBarControl
For Each CB In Application.CommandBars
Set CTL = CB.FindControl(ID:=3, recursive:=True)
If Not CTL Is Nothing Then
CTL.OnAction = "MySave"
End If
Next
Application.OnKey "^S", "MySave"
End Sub

Sub ReleaseSave()
Dim CB As CommandBar
Dim CTL As CommandBarControl
For Each CB In Application.CommandBars
Set CTL = CB.FindControl(ID:=3, recursive:=True)
If Not CTL Is Nothing Then
CTL.OnAction = ""
End If
Next
Application.OnKey "^S"
End Sub

and in ThisWorkbook module

Private Sub Workbook_Activate()
GrabSave
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ReleaseSave
End Sub

Private Sub Workbook_Open()
GrabSave
End Sub


Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is it Saving? Jeff Excel Discussion (Misc queries) 2 September 11th 09 09:34 PM
Automaticly saving formula's to values when saving Gunti Excel Discussion (Misc queries) 8 November 11th 08 09:34 AM
saving Arnie New Users to Excel 0 May 16th 08 12:24 PM
saving as an add-in? Howard Excel Worksheet Functions 1 February 1st 08 12:06 AM
A: saving Curt Excel Discussion (Misc queries) 5 April 11th 07 04:10 AM


All times are GMT +1. The time now is 11:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"