Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default overwrite Excel SaveAs function from File menu

When user click on SaveAs from File menu in excel, I would
like to send a message to the user that they are not
allowed to rename the file with a new file name to
U:\company and Save button will be disabled right away.
However the message should not popup if the user save the
file to any foler other than U:\company

Any idea on how to accomplish this?
Thank you.
Susie
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default overwrite Excel SaveAs function from File menu

I think that this'll work, but test it.

Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim myFileName As Variant
Dim okFolderName As String
Dim resp As Long

okFolderName = "U:\company"

'we'll do the saving--stop excel from trying to do it.
Cancel = True

If SaveAsUI Then
myFileName = Application.GetSaveAsFilename _
(InitialFileName:=ThisWorkbook.FullName, _
filefilter:="Excel Files, *.xls")
If myFileName = False Then
Exit Sub
Else
If LCase(Left(myFileName, Len(okFolderName))) < LCase(okFolderName)
Then
MsgBox "Cannot save here"
Exit Sub
Else
'do nothing
End If
End If
Else
myFileName = ThisWorkbook.FullName
End If

resp = vbYes
If SaveAsUI Then
If Dir(myFileName) < "" Then
resp = MsgBox(prompt:="Overwrite existing file?", Buttons:=vbYesNo)
End If
End If

If resp = vbYes Then
With Application
.EnableEvents = False
.DisplayAlerts = False
End With
Me.SaveAs Filename:=myFileName, FileFormat:=xlNormal
With Application
.DisplayAlerts = True
.EnableEvents = True
End With
End If

End Sub


This code goes in the ThisWorkbook module--not a general module.




susie wrote:

When user click on SaveAs from File menu in excel, I would
like to send a message to the user that they are not
allowed to rename the file with a new file name to
U:\company and Save button will be disabled right away.
However the message should not popup if the user save the
file to any foler other than U:\company

Any idea on how to accomplish this?
Thank you.
Susie


--

Dave Peterson

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
Excel File Overwrite GradAsh10 Excel Discussion (Misc queries) 1 January 18th 10 04:13 PM
retrieving of overwrite excel file? PLS! need help. Excel Discussion (Misc queries) 1 October 10th 05 10:34 AM
Save and Saveas Greyed out on tool bar and file menu Shareena Howley Setting up and Configuration of Excel 1 July 5th 05 01:02 PM
Excel prompts me to save a copy or overwrite file. Vinny Excel Worksheet Functions 0 May 20th 05 03:05 PM
Q: overwrite during saveas JIM.H. Excel Discussion (Misc queries) 1 January 5th 05 07:27 PM


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

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

About Us

"It's about Microsoft Excel"