Question : Cell Masking in Excel

I am trying to write a macro to read a cell containing passwords from an Excel sheet for Multiple database connections(these are dynamic and can be to multiple databases).

Is there a way to Mask the cell so that the users who open the Spreadsheet should not be able to read the cell but it must be editable, and should be read from the Macro?

Answer : Cell Masking in Excel

Here is a complete solution that works like you want.

From your project Explorer in VBA, hide a sheet as the xlSheetVeryHidden (for the Visibility property).
From a visible sheet, select a cell that will be available to users who will change the password.

From the visible sheet code form, add this code:
-----
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    If (Target.Column = 2 And Target.Row = 1) Then
        Dim newPassword: newPassword = Target.FormulaR1C1
        Target.FormulaR1C1 = ""
        Application.ActiveWorkbook.Worksheets(2).Cells(1, 1).FormulaR1C1 = newPassword
    End If
   
End Sub
-----
Make sure that the Column (2 in my example) and the Row (1 in my example) will fit your password cell.
Also, change the index of your hidden worksheet to the appropriate one (2 in my case - it's a zero based index).

To retreive your hidden password, use this code:

Application.ActiveWorkbook.Worksheets(2).Cells(1, 1).FormulaR1C1

Don't forget to set the appropriate index there also.

Finaly don't forget to put a password on your project so other people cannot change the sheet visibility.

========

I think it's the only way that you could acheive exactly what you want.

PS. Of course you can replace the password with ******** instead of clearing the text like in my example.
Random Solutions  
 
programming4us programming4us