Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 27th, 2008, 05:44 AM
Registered User
Join Date: Nov 2008
Location: Shanghai, , China.
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?

Dim hMenu As Long

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

Reply With Quote
  #2 (permalink)  
Old December 22nd, 2008, 10:15 AM
Friend of Wrox
Points: 513, Level: 8
Points: 513, Level: 8 Points: 513, Level: 8 Points: 513, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Feb 2007
Location: Davenport, IA, USA.
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts

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:

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.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 09:51 PM.

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