R
Rich
Hello,
I think I am nearing completion of a little VBA project I have been
working on to 1st: Force macros to run, by hiding all sheets except a
sheet called "Welcome", and 2nd: check the date entered on another to
be hidden sheet called "Data" against the 'Now' date. If incorrect,
then workbook closes after vbOk dialogue.
I am still learning, and at the moment I am having a mental meltdown
over why my code isn't doing a few things that I thought it would
have. Please examine:
Sub workbook_before_close()
Dim ws As Worksheet
ActiveSheet.Select
For Each ws In Worksheets
ws.Visible = xlVeryHidden
Next ws
Call Show_Welcome
End Sub
Sub workbook_open()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Visible = True
Next ws
Call Hide_Datasheet
Call Hide_Welcome
If Now >= Worksheets("Data").Range("A1") Then
Confirm = MsgBox("This workbook has expired. Please contact
Suppport for further assistance.", vbInformation + vbOKOnly, "Workbook
Expiry")
If Confirm = vbOKOnly Then
Application.Quit
Else: Application.Quit
End If
End If
End Sub
Sub Hide_Datasheet()
Worksheets("Data").Visible = xlVeryHidden
End Sub
Sub Show_Welcome()
Worksheets("Welcome").Visible = xlSheetVisible
End Sub
Sub Hide_Welcome()
Worksheets("Welcome").Visible = xlVeryHidden
End Sub
I know by looking at it it probably isn't the most efficient looking
code. May I kindly request someone fro this talented arena looking
over the above code, and entering comments where you think it could be
better (or fixed?) If you could avoid it, please don't enter too much
new code as that would just confuse me (Unless you belive it is really
required!)
Thank you for your help, it is greatly appreciated.
p.s. all subs are under the ThisWorkbook section
I think I am nearing completion of a little VBA project I have been
working on to 1st: Force macros to run, by hiding all sheets except a
sheet called "Welcome", and 2nd: check the date entered on another to
be hidden sheet called "Data" against the 'Now' date. If incorrect,
then workbook closes after vbOk dialogue.
I am still learning, and at the moment I am having a mental meltdown
over why my code isn't doing a few things that I thought it would
have. Please examine:
Sub workbook_before_close()
Dim ws As Worksheet
ActiveSheet.Select
For Each ws In Worksheets
ws.Visible = xlVeryHidden
Next ws
Call Show_Welcome
End Sub
Sub workbook_open()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Visible = True
Next ws
Call Hide_Datasheet
Call Hide_Welcome
If Now >= Worksheets("Data").Range("A1") Then
Confirm = MsgBox("This workbook has expired. Please contact
Suppport for further assistance.", vbInformation + vbOKOnly, "Workbook
Expiry")
If Confirm = vbOKOnly Then
Application.Quit
Else: Application.Quit
End If
End If
End Sub
Sub Hide_Datasheet()
Worksheets("Data").Visible = xlVeryHidden
End Sub
Sub Show_Welcome()
Worksheets("Welcome").Visible = xlSheetVisible
End Sub
Sub Hide_Welcome()
Worksheets("Welcome").Visible = xlVeryHidden
End Sub
I know by looking at it it probably isn't the most efficient looking
code. May I kindly request someone fro this talented arena looking
over the above code, and entering comments where you think it could be
better (or fixed?) If you could avoid it, please don't enter too much
new code as that would just confuse me (Unless you belive it is really
required!)
Thank you for your help, it is greatly appreciated.
p.s. all subs are under the ThisWorkbook section