Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 27th, 2008, 05:44 AM
Registered User
 
Join Date: Nov 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Enable Excel Close Botton

I want to make the excel program close botton disable not the vb form close botton, you know.
The initial thought in my mind is to use API program:

Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long

Public Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long

But how to write follow this?
is

Dim hMenu As Long

hMenu = GetSystemMenu(Application.hWndExcelApp, 0)
Call DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)
right?

 
Old December 22nd, 2008, 10:15 AM
Friend of Wrox
 
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Using the API seems like a lot of needless effort. It would be easier to just cancel the close in the Workbook_BeforeClose object module:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
 
'Prevents workbook from closing.
  Cancel = True
 
End Sub
Thing is neither this nor the API will stop a determined individual. With this method you can also notify the user as to why before ending the sub.





Similar Threads
Thread Thread Starter Forum Replies Last Post
LOGOUT BOTTON+SERVLETS kotaiah J2EE 1 January 2nd, 2007 01:44 AM
Enable Update and Enable Delete check boxes don't mihabib ASP.NET 2.0 Basics 2 December 7th, 2006 11:44 AM
Disable/Enable Excel Add-ins madda Excel VBA 6 October 12th, 2005 05:53 AM
Run macro when exit/close excel dgilford Excel VBA 1 September 8th, 2005 02:42 AM
Open & Close Excel file in the background mikezhang Classic ASP Professional 0 March 17th, 2004 08:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.