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: 6,582
Default Help Needed! VB Code to "Save As..."

Here's a simple implementation of the BeforeSave that takes into account
whether the user wants to Save As (SaveAsUI = True) or just Save (SaveAsUI =
False):

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cancel = True
If SaveAsUI Then
' user wants to Save As
Application.EnableEvents = False
Application.Dialogs(xlDialogSaveAs).Show
Application.EnableEvents = True
Else
' user wants to Save
Application.EnableEvents = False
ThisWorkbook.Save
Application.EnableEvents = True
End If
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Elkar" wrote in message
...
I have a workbook that I am requiring Macros to be activated in order to
use.
I've managed to do this by using the following code in the BeforeSave
event:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cancel = True
Application.EnableEvents = False
Application.ScreenUpdating = False
ActiveWorkbook.Unprotect ("password")
Worksheets("Warning").Visible = True
Worksheets("Time Sheet").Visible = False
Worksheets("Data Sheet").Visible = False
ActiveWorkbook.Protect ("password")
ActiveWorkbook.Save
Application.EnableEvents = True
ActiveWorkbook.Unprotect ("password")
Worksheets("Time Sheet").Visible = True
Worksheets("Data Sheet").Visible = True
Worksheets("Warning").Visible = False
ActiveWorkbook.Protect ("password")
Application.ScreenUpdating = True
ThisWorkbook.Saved = True
End Sub

This works great, except that the user can't use "Save As..." to change
the
filename. Even if I use the line Activeworkbook.SaveAs, it still only
saves
over the original filename. How can I modify this so that Save As will
work?

Any help is much appreciated. Thanks in advance!
Elkar



 
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
Selecting "Save As" adds "Copy of" to file name- MS Excel 2007 ronhansen Excel Discussion (Misc queries) 1 November 15th 09 09:33 PM
"CELL("FILENAME") NOT UPDATE AFTER "SAVE AS" ACTION yossie6 Excel Discussion (Misc queries) 1 June 16th 08 12:16 PM
"Save" and "Save As" options greyed out - "Save as Webpage" option Bill Excel Discussion (Misc queries) 0 January 16th 07 04:47 PM
"Subscript out of range" error for: Workbooks("Test1.xls").Save Just12341234 Excel Programming 2 June 17th 05 03:16 PM
save and restore "Workbook Menu Bar" & "Cell" menus Jeff Higgins Excel Programming 2 February 14th 05 01:33 AM


All times are GMT +1. The time now is 05:29 AM.

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"