LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default Canceling Workbook Before_Save event

Hello All,

First, thank you to all the contributors to this site as it has been a
valuable resource for learning and coding in VBA.

I have a problem I have not been able to resolve. I have the code
below in a workbook (Voucher Form.xls) that is saved on a network
drive. It is a read only workbook, reps. in our call center use to
process customer transactions.

I want to prevent the rep from saving the file within network directory
the template is stored in. I am using the BeforeSave event to give the
rep an opportunity to save to the designated desktop folder or cancel
the save operation.

Problem: the BeforeSave event does not appear to be the correct place
for this code. It ignores the cancel selection and continues the save
operation.

Any suggestions on the placement or modification of this code so that
Cancel exists the sub would be greatly appreciated. Thanks.

Alan


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
'This macro and function force file save location and default name
Dim strPath
Dim fname
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "File will be saved to a ""Saved Vouchers"" folder" & vbCr & _
"on your desktop. Do you wish to Continue?"
Style = vbYesNo + vbExclamation + vbDefaultButton2 ' Define buttons.
Title = "File Save" ' Define title.
'Help = "DEMO.HLP" ' Define Help file.
'Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbNo Then ' User chose Yes.
Exit Sub
Else ' User chose No.
fname = Range("Acct_1").Value & " " & ThisWorkbook.Name
strPath = Environ("userprofile") & Environ("HomePath") & _
"Desktop\"
On Error Resume Next
MkDir strPath & "Saved Vouchers"
strPath = Environ("userprofile") & Environ("HomePath") & _
"Desktop\Saved Vouchers\"
ActiveWorkbook.SaveAs _
Filename:=strPath & fname, _
FileFormat:=xlNormal, CreateBackup:=False
End If
End Sub
Private Sub Create_Dir()
Dim wShell, fso, strFldr As String, MyDrive As String
Set wShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
strFldr = wShell.SpecialFolders("Desktop")
MyDrive = Left(strFldr, 3)
ChDrive (MyDrive)
ChDir (strFldr)
fso.CreateFolder ("Saved Vouchers")
End Sub

 
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
Problem with Before_Save Macro Jay Excel Discussion (Misc queries) 5 May 18th 06 06:47 PM
Keep Before_Save from running Alex Excel Programming 1 March 7th 06 11:49 PM
Before_Save event quartz[_2_] Excel Programming 3 September 20th 05 12:36 AM
Canceling SaveAs dialog box without saving workbook CDotWin Excel Programming 3 July 24th 04 01:09 AM
Need Before_Save code Phil Hageman Excel Programming 13 July 10th 03 11:55 AM


All times are GMT +1. The time now is 07:56 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"