Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
 
Posts: n/a
Default Hide worksheets before close

I have a workbook with multiple sheets that I would like to Hide before
close. I am using a macro attached to a "Quit" button, but it does not
work.
I also have a Sub in ThisWorkbook, but I can't seem to call it

Sub Button14_Click_Quit()

Application.DisplayAlerts = False

Worksheets("A Detail").Visible = False
Worksheets("A Metrics").Visible = False
Worksheets("B DV Detail").Visible = False
Worksheets("B DV Metrics").Visible = False
Worksheets("B Detail").Visible = False
Worksheets("B Metrics").Visible = False
Worksheets("C Metrics").Visible = False
Worksheets("C Detail").Visible = False
Worksheets("D Detail").Visible = False
Worksheets("D Metrics").Visible = False

Workbooks("KeyCustomerMetrics.XLS").Close


End Sub


The code in ThisWorkbook:

Public Sub Workbook_BeforeClose(Cancel As Boolean)

Worksheets("A Detail").Visible = False
Worksheets("A Metrics").Visible = False
Worksheets("B DV Detail").Visible = False
Worksheets("B DV Metrics").Visible = False
Worksheets("B Detail").Visible = False
Worksheets("B Metrics").Visible = False
Worksheets("C Metrics").Visible = False
Worksheets("C Detail").Visible = False
Worksheets("D Detail").Visible = False
Worksheets("D Metrics").Visible = False
End Sub

If I click on File, Close, it works--not sure what i am doing wrong....
any help would be much appreciated

J

  #2   Report Post  
Posted to microsoft.public.excel.newusers
Chip Pearson
 
Posts: n/a
Default Hide worksheets before close

You can't just make up event procedure names. You must use the
event names provided by VBA. Assuming your button is named
Button14, change

Sub Button14_Click_Quit()
to
Sub Button14_Click()


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


wrote in message
oups.com...
I have a workbook with multiple sheets that I would like to Hide
before
close. I am using a macro attached to a "Quit" button, but it
does not
work.
I also have a Sub in ThisWorkbook, but I can't seem to call it

Sub Button14_Click_Quit()

Application.DisplayAlerts = False

Worksheets("A Detail").Visible = False
Worksheets("A Metrics").Visible = False
Worksheets("B DV Detail").Visible = False
Worksheets("B DV Metrics").Visible = False
Worksheets("B Detail").Visible = False
Worksheets("B Metrics").Visible = False
Worksheets("C Metrics").Visible = False
Worksheets("C Detail").Visible = False
Worksheets("D Detail").Visible = False
Worksheets("D Metrics").Visible = False

Workbooks("KeyCustomerMetrics.XLS").Close


End Sub


The code in ThisWorkbook:

Public Sub Workbook_BeforeClose(Cancel As Boolean)

Worksheets("A Detail").Visible = False
Worksheets("A Metrics").Visible = False
Worksheets("B DV Detail").Visible = False
Worksheets("B DV Metrics").Visible = False
Worksheets("B Detail").Visible = False
Worksheets("B Metrics").Visible = False
Worksheets("C Metrics").Visible = False
Worksheets("C Detail").Visible = False
Worksheets("D Detail").Visible = False
Worksheets("D Metrics").Visible = False
End Sub

If I click on File, Close, it works--not sure what i am doing
wrong....
any help would be much appreciated

J



  #3   Report Post  
Posted to microsoft.public.excel.newusers
 
Posts: n/a
Default Hide worksheets before close

Guess I should explain better.
I created the button using the Forms toolbar, then right-clicked to
assign macro. I created the macro and re-named it, and that is where
the name came from.
The workbook closed when i clicked the button, but the sheets did not
hide.
I re-named the procedure and re-assigned the button macro, but still,
the sheets remained visible.

Got it--as i worked on it, i realized that i didn't save before
close....now it works

thanks for the help,--your website is great, by the way

J

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
Duplicate Worksheets mlofton Excel Discussion (Misc queries) 1 September 7th 05 02:58 PM
closing 1 file at a time Keith G Hicks Excel Discussion (Misc queries) 4 September 4th 05 02:16 AM
Changing a Link Mid-way Across Worksheets Frosty Excel Worksheet Functions 0 August 25th 05 12:03 AM
Excel shoud not close all active books when clicking close button technomike Excel Discussion (Misc queries) 0 June 10th 05 05:35 PM
close (hide) toolbars Anthony Excel Discussion (Misc queries) 7 June 5th 05 03:19 PM


All times are GMT +1. The time now is 08:09 PM.

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"