Hiding Spreadsheet Automatically

ankrups

Board Regular
Joined
Mar 14, 2006
Messages
125
Office Version
  1. 2021
Platform
  1. Windows
Hi there,
one simple question...how can we automated process of hiding the selected worksheet when we close the workbook....

thanks


ankit..
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
put an event code under thisworkbook_before close somethinglike this
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.EnableEvents = False
Worksheets("sheet1").Visible = False
Application.Enableevents = True
End Sub
 
Upvote 0
just a thought pop up in mind...Can we create such formula that we write only once...in VBA...and in future we just call this formula by clikcing VBA Code of related worksheet....


thanks..
 
Upvote 0
put it under FUNCTION and NOT as sub.

this is an example
see this functin

Public Function monthname(x As Long) As String
'use function as personal.xls!monthname(some no.)
If x = 1 Then monthname = "jan"
If x = 2 Then monthname = "feb"
If x = 3 Then monthname = "mar"
If x = 4 Then monthname = "apr"
If x = 5 Then monthname = "may"
If x = 6 Then monthname = "jun"
If x = 7 Then monthname = "july"
If x = 8 Then monthname = "aug"
If x = 9 Then monthname = "sep"
If x = 10 Then monthname = "oct"
If x = 11 Then monthname = "nov"
If x = 12 Then monthname = "dec"
End Function
This functin I have parked in personal.xls file vb editor so that it can be used in any workbook.
now in any cell in any sheet in any workbook type

=PERSONAL.XLS!monthname(3)
note exclamation mark.
the result will be
mar
 
Upvote 0

Forum statistics

Threads
1,217,481
Messages
6,136,902
Members
450,029
Latest member
MissQuotation

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top