Hiding Spreadsheet Automatically

ankrups

Board Regular
Joined
Mar 14, 2006
Messages
105
Hi there,
one simple question...how can we automated process of hiding the selected worksheet when we close the workbook....

thanks


ankit..
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824
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
 

ankrups

Board Regular
Joined
Mar 14, 2006
Messages
105
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..
 

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824
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
 

Forum statistics

Threads
1,137,205
Messages
5,680,184
Members
419,887
Latest member
Vasokir

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
Top