#1   Report Post  
Posted to microsoft.public.excel.misc
dan dan is offline
external usenet poster
 
Posts: 866
Default Disable Close Button

I wanted to disable the close button in the upper right hand corner of Excel
so users would have to use a button on the spreadsheet (assigned to a macro)
to close the worksheet. I used the following code:

Private Sub WorkBook_BeforeClose (Cancel As Boolean)
Cancel = True
End Sub

The code works great but now my macro button will not work and I can't close
the worksheet at all. Can you help me out? I'd appreciate it!
--
Dan N
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Disable Close Button

In your code that closes the workbook, you'll want to make sure that you don't
allow the workbook_beforeclose event to run normally (cancel = true).

I'd put this in at the top of a General Module:

Public BlkProc as Boolean

By declaring this variable outside a procedure and making it public, each
routine can read the value in that variable.

Then in your code that closes the workbook:

BlkProc = true
thisworkbook.close savechanges:=true 'or false???

And then change the workbook_beforeclose event to look at that variable:

Private Sub WorkBook_BeforeClose (Cancel As Boolean)
if blkproc = true then
'do nothing, let the workbook close
else
Cancel = True
end if
End Sub



Dan wrote:

I wanted to disable the close button in the upper right hand corner of Excel
so users would have to use a button on the spreadsheet (assigned to a macro)
to close the worksheet. I used the following code:

Private Sub WorkBook_BeforeClose (Cancel As Boolean)
Cancel = True
End Sub

The code works great but now my macro button will not work and I can't close
the worksheet at all. Can you help me out? I'd appreciate it!
--
Dan N


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
dan dan is offline
external usenet poster
 
Posts: 866
Default Disable Close Button

Dave

Thank you for your response. I follow everything you said except the General
Module part. I'm not sure what a general module is and exactly where to put
the code
Public BlkProc as Boolean. I put it in the ThisWorkbook module but it is
still not responding.
--
Dan N


"Dave Peterson" wrote:

In your code that closes the workbook, you'll want to make sure that you don't
allow the workbook_beforeclose event to run normally (cancel = true).

I'd put this in at the top of a General Module:

Public BlkProc as Boolean

By declaring this variable outside a procedure and making it public, each
routine can read the value in that variable.

Then in your code that closes the workbook:

BlkProc = true
thisworkbook.close savechanges:=true 'or false???

And then change the workbook_beforeclose event to look at that variable:

Private Sub WorkBook_BeforeClose (Cancel As Boolean)
if blkproc = true then
'do nothing, let the workbook close
else
Cancel = True
end if
End Sub



Dan wrote:

I wanted to disable the close button in the upper right hand corner of Excel
so users would have to use a button on the spreadsheet (assigned to a macro)
to close the worksheet. I used the following code:

Private Sub WorkBook_BeforeClose (Cancel As Boolean)
Cancel = True
End Sub

The code works great but now my macro button will not work and I can't close
the worksheet at all. Can you help me out? I'd appreciate it!
--
Dan N


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Disable Close Button

Select your project in the VBE.
Insert|module
and put the declaration there.

Dan wrote:

Dave

Thank you for your response. I follow everything you said except the General
Module part. I'm not sure what a general module is and exactly where to put
the code
Public BlkProc as Boolean. I put it in the ThisWorkbook module but it is
still not responding.
--
Dan N

"Dave Peterson" wrote:

In your code that closes the workbook, you'll want to make sure that you don't
allow the workbook_beforeclose event to run normally (cancel = true).

I'd put this in at the top of a General Module:

Public BlkProc as Boolean

By declaring this variable outside a procedure and making it public, each
routine can read the value in that variable.

Then in your code that closes the workbook:

BlkProc = true
thisworkbook.close savechanges:=true 'or false???

And then change the workbook_beforeclose event to look at that variable:

Private Sub WorkBook_BeforeClose (Cancel As Boolean)
if blkproc = true then
'do nothing, let the workbook close
else
Cancel = True
end if
End Sub



Dan wrote:

I wanted to disable the close button in the upper right hand corner of Excel
so users would have to use a button on the spreadsheet (assigned to a macro)
to close the worksheet. I used the following code:

Private Sub WorkBook_BeforeClose (Cancel As Boolean)
Cancel = True
End Sub

The code works great but now my macro button will not work and I can't close
the worksheet at all. Can you help me out? I'd appreciate it!
--
Dan N


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
dan dan is offline
external usenet poster
 
Posts: 866
Default Disable Close Button

Dave,

It is working perfectly! Thank you so much. I really appreciate your help
and quick response.
--
Dan N


"Dave Peterson" wrote:

Select your project in the VBE.
Insert|module
and put the declaration there.

Dan wrote:

Dave

Thank you for your response. I follow everything you said except the General
Module part. I'm not sure what a general module is and exactly where to put
the code
Public BlkProc as Boolean. I put it in the ThisWorkbook module but it is
still not responding.
--
Dan N

"Dave Peterson" wrote:

In your code that closes the workbook, you'll want to make sure that you don't
allow the workbook_beforeclose event to run normally (cancel = true).

I'd put this in at the top of a General Module:

Public BlkProc as Boolean

By declaring this variable outside a procedure and making it public, each
routine can read the value in that variable.

Then in your code that closes the workbook:

BlkProc = true
thisworkbook.close savechanges:=true 'or false???

And then change the workbook_beforeclose event to look at that variable:

Private Sub WorkBook_BeforeClose (Cancel As Boolean)
if blkproc = true then
'do nothing, let the workbook close
else
Cancel = True
end if
End Sub



Dan wrote:

I wanted to disable the close button in the upper right hand corner of Excel
so users would have to use a button on the spreadsheet (assigned to a macro)
to close the worksheet. I used the following code:

Private Sub WorkBook_BeforeClose (Cancel As Boolean)
Cancel = True
End Sub

The code works great but now my macro button will not work and I can't close
the worksheet at all. Can you help me out? I'd appreciate it!
--
Dan N

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Disable Close Button

Glad you got it working.

Dan wrote:

Dave,

It is working perfectly! Thank you so much. I really appreciate your help
and quick response.
--
Dan N

"Dave Peterson" wrote:

Select your project in the VBE.
Insert|module
and put the declaration there.

Dan wrote:

Dave

Thank you for your response. I follow everything you said except the General
Module part. I'm not sure what a general module is and exactly where to put
the code
Public BlkProc as Boolean. I put it in the ThisWorkbook module but it is
still not responding.
--
Dan N

"Dave Peterson" wrote:

In your code that closes the workbook, you'll want to make sure that you don't
allow the workbook_beforeclose event to run normally (cancel = true).

I'd put this in at the top of a General Module:

Public BlkProc as Boolean

By declaring this variable outside a procedure and making it public, each
routine can read the value in that variable.

Then in your code that closes the workbook:

BlkProc = true
thisworkbook.close savechanges:=true 'or false???

And then change the workbook_beforeclose event to look at that variable:

Private Sub WorkBook_BeforeClose (Cancel As Boolean)
if blkproc = true then
'do nothing, let the workbook close
else
Cancel = True
end if
End Sub



Dan wrote:

I wanted to disable the close button in the upper right hand corner of Excel
so users would have to use a button on the spreadsheet (assigned to a macro)
to close the worksheet. I used the following code:

Private Sub WorkBook_BeforeClose (Cancel As Boolean)
Cancel = True
End Sub

The code works great but now my macro button will not work and I can't close
the worksheet at all. Can you help me out? I'd appreciate it!
--
Dan N

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
Reply
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
Use the Merge & Center Button with unprotected Cells - sheet prote Dennis Cantellops Setting up and Configuration of Excel 1 September 22nd 06 12:49 AM
Disable Exit button on a UserForm Noemi Excel Discussion (Misc queries) 1 September 14th 06 09:37 PM
Disable "save" option on close. PG Excel Discussion (Misc queries) 2 September 6th 06 12:15 AM
Userform + close button Chip Smith Excel Discussion (Misc queries) 2 April 1st 06 09:35 AM
VBA: Disable Frame and Radio Buttons based on Another Radio Button Being True Mcasteel Excel Worksheet Functions 2 October 29th 04 07:06 PM


All times are GMT +1. The time now is 11:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"