Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

Clear Textbox when workbook is closed

$
0
0

In my Workbook I have a Worksheet which is hidden with password protection.

In Sheet1 I have a CommandButton control, which makes Sheet2 visible when the password is entered in TextBox1.

In my VBA Code, Sheet2 is hidden when I close the Workbook, but if I open it again the password is still visible in TextBox1.

Is there any possibility to clear TextBox1 when I close the workbook?

This is my code for when I close the workbook:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Worksheets("Sheet2").Visible = xlSheetVeryHidden
End Sub

This is my code for hiding the other sheets in the workbook:

Option Explicit

Private Sub CommandButton1_Click()
    If TextBox1.Text = "password" Then
        Worksheets("Sheet2").Visible = xlSheetVisible
    Else
        Worksheets("Sheet2").Visible = xlSheetVeryHidden
    End If
End Sub

Private Sub UserForm_Initialize()
    TextBox1.PasswordChar = "*"
End Sub

Viewing all articles
Browse latest Browse all 88835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>