Link to home
Start Free TrialLog in
Avatar of camper12
camper12

asked on

vba fade sheet

Hi,

I am using the following code on opening an excel workbook. I am hiding some sheets and opening only one of the sheets with the following code.

Additionally, I would like to fade out the sheet on opening.

Private Sub Workbook_Open()

For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> Sheet8.Name Then
        ws.Visible = xlSheetVeryHidden
    End If
 Next
 
 With DisclaimerForm
    .StartUpPosition = 0
    .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
    .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
    .Show
 End With
 Application.ScreenUpdating = False
End Sub

Open in new window


Also, there is a popup on opening. If the user selects the checkbox I use the following code. As soon as the user checks the check box, I would like to unfade everything.
Private Sub CheckBox1_Click()
Dim ws As Worksheet
 
Application.ScreenUpdating = False
 
If Me.CheckBox1.Value = True Then
    Application.ScreenUpdating = False
    'ThisWorkbook.Unprotect ""
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> Sheet8.Name Then
            ws.Visible = xlSheetVisible
        End If
    Next
    End If
    Unload Me
End Sub

Open in new window


How should I accomplish fading and unfading?

Thanks
Avatar of Roy Cox
Roy Cox
Flag of United Kingdom of Great Britain and Northern Ireland image

You can't fade a sheet as far as I know. can hide the sheet or even the application, although I would not recommend hiding the application unless you know what you are doing.

This may act as a workaround
HidebehindUserForm.xlsm
All you can do is, hide all the rows and columns when the file opens and unhide them all when the checkbox is clicked.
Private Sub Workbook_Open()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> Sheet8.Name Then
        ws.Visible = xlSheetVeryHidden
    End If
 Next
 
 Sheet8.Columns.Hidden = True
 Sheet8.Rows.Hidden = True
 
 With DisclaimerForm
    .StartUpPosition = 0
    .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
    .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
    .Show
 End With
 Application.ScreenUpdating = True
End Sub

Open in new window


Private Sub CheckBox1_Click()
Dim ws As Worksheet
Application.ScreenUpdating = False

If Me.CheckBox1.Value = True Then
    'ThisWorkbook.Unprotect ""
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> Sheet8.Name Then
            ws.Visible = xlSheetVisible
        End If
    Next
    Sheet8.Columns.Hidden = False
    Sheet8.Rows.Hidden = False
    Unload Me
End If
Application.ScreenUpdating = True
End Sub

Open in new window

Excel worskheets arn't displayed on top of each other.
So fading one make no sens.
The author says that all sheets but one are hidden. One sheet must always be visible but I don't really understand why it should "fade">
How about inserting a rectangle shape with grey fill and set to 50% transparency? The sheet behind will then be visible but hazy through the grey shape.

The grey shape can then be deleted when CheckBox is ticked.

Alternatively, the check box will set a value in a cell; you could use Conditional Formatting based on the Check Box cell value to set the font of all cells to pale grey until Check Box is ticked resetting font to standard colour.
Avatar of camper12
camper12

ASKER

Hi,

This is giving me an error: Run-time error '1004'. Application-defined or object-defined error.
Private Sub Workbook_Open()

For Each ws In ThisWorkbook.Worksheets
    If ws.Name <> ShInputForm.Name Then
        ws.Visible = xlSheetVeryHidden
    End If
Next
 ThisWorkbook.Unprotect ""
 ShInputForm.Columns.Hidden = True
 ShInputForm.Rows.Hidden = True
 With DisclaimerForm
    .StartUpPosition = 0
    .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
    .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
    .Show
 End With
 
 
 Application.ScreenUpdating = True
End Sub

Open in new window

In the following lines...
 ShInputForm.Columns.Hidden = True
 ShInputForm.Rows.Hidden = True

Open in new window

ShInputForm should be either the Sheet Code Name or a worksheet variable properly set before used.

If ShInputForm is the sheet name you should use it like...
Sheets("ShInputForm").Columns.Hidden = True

Open in new window


Same way change the relevant lines in other code as well.

Refer to the attached for more details.
Camper.xlsm
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.