Forum Home
Press F1
 
Thread ID: 9061 2001-05-04 22:05:00 Excel Workbook, opening to the correct Daysheet. Guest (0) Press F1
Post ID Timestamp Content User
12174 2001-05-04 22:05:00 In my workbook, I have 6 sheets, 1 each for Mon - Fri plus a macro sheet.

Is there a macro I can use to get the Workbooki to open on the appropiate day sheet?

Thanks in anticipation....John.

jhw@xtra.co.nz
Guest (0)
12175 2001-05-05 06:34:00 This can be accomplished with one simple line of code. After creating a new module in your workbook paste the following code:

'Macro to select day sheet
Sub AutoOpen()
Sheets(WeekDay(Date) - 1).Activate
End Sub

This macro will run each time you open the workbook. This method has restrictions, the day sheets must be kept in order (Mon, Tue, Wed, Thur, Fri) for the correct sheet to be selected and if the workbook is opened on a non weekday the macro will give an error since there are only 5 sheets to select.

The second macro below provides much more control and does not matter if the sheets are not in order.

Sub AutoOpen()
If (WeekDay(Date) - 1 = 1) Then Sheets('Monday').Activate
If (WeekDay(Date) - 1 = 2) Then Sheets('Tuesday').Activate
If (WeekDay(Date) - 1 = 3) Then Sheets('Wednesday').Activate
If (WeekDay(Date) - 1 = 4) Then Sheets('Thursday').Activate
If (WeekDay(Date) - 1 = 5) Then Sheets('Friday').Activate
End Sub


Have fun,
Tristan
Guest (0)
12176 2001-05-05 07:03:00 Whoops, that should have read:

Sub Auto_open()
If (WeekDay(Date) - 1 = 1) Then Sheets('Monday').Activate
If (WeekDay(Date) - 1 = 2) Then Sheets('Tuesday').Activate
If (WeekDay(Date) - 1 = 3) Then Sheets('Wednesday').Activate
If (WeekDay(Date) - 1 = 4) Then Sheets('Thursday').Activate
If (WeekDay(Date) - 1 = 5) Then Sheets('Friday').Activate
End Sub
Guest (0)
1