dwilliamson1024

New Member
Joined
Dec 8, 2014
Messages
40
First of all, thanks to everyone who has helped me on my current project.

I currently have a code to prompt for password before saving a metrics file, which only a handful of people know the password (and not too many are bright enough here to look in VBA to find the password :ROFLMAO:)

I was asked to keep track of the users who go into the file. I can do this by one of two ways:
  1. get a time and user stamp on an external file and save it
  2. get a time and user stamp on a very hidden sheet and save it within the file itself (preferred)

I greatly prefer option 2 (as I don't want the user to be able to see another file open and put their name down and save, or I will get 500980 phone calls asking what it's doing :eek:.

Is there a way to use VBA to (when file first opens):
  • unhide the very hidden worksheet
  • put the user name and current time into the next available open row
  • very hide the worksheet again
  • save the file (but enter the password right away and click ok quick enough for the user to not notice it, or notice what the password is when it is typed into the prompt box for saving password.

Any ideas out there?

Thanks!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Yes; This probably could be done. Can you show your code that prompts for password and saves?

VBA can write to a hidden worksheet without making it visible.
 
Upvote 0
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim ans As String

ans = InputBox("This is a protected file. Please enter a password to allow saving", "Password Required", "******")

If ans <> "MY.PASSWORD.WE.ARE.USING.GOES.HERE" Then
MsgBox "Password incorrect. Sorry, only administrators have permission to save this file"
Cancel = True
End If

End Sub
 
Upvote 0
Change the name of the Hidden sheet to suit.

Code:
[color=darkblue]Dim[/color] ans    [color=darkblue]As[/color] [color=darkblue]String[/color]

[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Workbook_BeforeSave([color=darkblue]ByVal[/color] SaveAsUI [color=darkblue]As[/color] [color=darkblue]Boolean[/color], Cancel As [color=darkblue]Boolean[/color])
    
    [color=darkblue]If[/color] ans <> "MY.PASSWORD.WE.ARE.USING.GOES.HERE" [color=darkblue]Then[/color]
        ans = InputBox("This is a protected file. Please enter a password to allow saving", "Password Required", "******")
    
        [color=darkblue]If[/color] ans <> "MY.PASSWORD.WE.ARE.USING.GOES.HERE" [color=darkblue]Then[/color]
            MsgBox "Password incorrect. Sorry, only administrators have permission to save this file"
            Cancel = [color=darkblue]True[/color]
        [color=darkblue]End[/color] [color=darkblue]If[/color]
    [color=darkblue]End[/color] [color=darkblue]If[/color]
    ans = ""
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]

[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Workbook_Open()
    ans = "MY.PASSWORD.WE.ARE.USING.GOES.HERE"
    [color=darkblue]With[/color] Sheets([COLOR=#ff0000]"Sheet3"[/COLOR]).Range("A" & Rows.Count).End(xlUp)
        .Offset(1, 0).Value = Application.UserName
        .Offset(1, 1).Value = Now
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    ThisWorkbook.Save
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Good morning AlfaFrog.

Is there an easy way to put in an IF statement that would skip putting down my user name? I go in the file 15 times a day, and it will start to become cumbersome if its 800 of me and 50 of other users.

Also out of curiosity, how are you pasting in your code that way into the forum threads? I can't seem to find a post that explains that either. Thanks!
 
Upvote 0
Code:
[color=darkblue]Private[/color] [color=darkblue]Sub[/color] Workbook_Open()
    
    [color=darkblue]If[/color] Application.UserName <> [COLOR=#ff0000]"dwilliamson1024"[/COLOR] [color=darkblue]Then[/color]
        [color=darkblue]With[/color] Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp)
            .Offset(1, 0).Value = Application.UserName
            .Offset(1, 1).Value = Now
        [color=darkblue]End[/color] [color=darkblue]With[/color]
        ans = "MY.PASSWORD.WE.ARE.USING.GOES.HERE"
        ThisWorkbook.Save
    [color=darkblue]End[/color] [color=darkblue]If[/color]
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]

See my signature block below about the use of CODE tags.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top