|
-
Jan 22nd, 2008, 12:17 PM
#1
Re: Excel - Allows SaveAs Only
 Originally Posted by koolsid
Well in that case, Hack, would you like the user not to be able to exit by clicking on 'X' button? Each time the user clicks on the 'X' button, he will be prompted to do a Save As... If Yes then this should help...
vb Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not saveasUI = True Then
MsgBox "Please use Save As To Save this File"
Cancel = True
End If
End Sub
If you don't want the user to exit by clickin on the 'X' button then simply use the above code without the MSGBOX....
Hope this will satisfy the department manager 
What is: saveasUI?
Is that a variable I need to declare or Excel will yell at me?
-
Jan 22nd, 2008, 12:20 PM
#2
Re: Excel - Allows SaveAs Only
 Originally Posted by Hack
What is: saveasUI?
Is that a variable I need to declare or Excel will yell at me?
Its from the BeforeSave event. Set it depending on if you want the Save As dialog box to be displayed or not
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 22nd, 2008, 12:24 PM
#3
Re: Excel - Allows SaveAs Only
 Originally Posted by Hack
What is: saveasUI?
Is that a variable I need to declare or Excel will yell at me?
Nah you do not need to declare it. The code below can be used to stop any users saving a Workbook as another name and another location. The code must be placed in the Private Module of the Workbook Object (ThisWorkbook). The fastest way to get there is to right click on the Excel icon, top left next to File and select View Code. It is in here you should place the code below and then save the Workbook. So long as the Workbook is opened with macros enabled the code will fire anytime any user tries to clcik on the 'X' button.
hope this helps...
edit: Ah Rob beat me to it
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|