Results 1 to 2 of 2

Thread: Protect created or saved file as encrypt documents with my user name only

  1. #1

    Protect created or saved file as encrypt documents with my user name only

    Dear, Sirs,

    I would like to protect my files whenever I create or open then save any excel file in my computer (with user say loveguy1977 + other words say 123456) as encrypt documents and that macro should be only in my personal macro (not as a vba in each excel bez it is easy to hack vba password)

    Meaning the password will be (loveguy1977123456)

    So no body will be able to open my files if copied or sent to them by mistake at the same time when it opened in my computer (user loveguy1977) it won't ask me for the password bez automatically it will consider the password as my user name + other word which be programed in my personal macro.

    But if it open in another user then it will ask for the password which is (loveguy1977123456).

    Please help me in this, it will help me and others as well. I really i'm need for it

    Thank you
    Last edited by loveguy1977; 04-08-2012 at 02:53 PM.

  2. #2
    It seems that is diffcult to do what I wish.

    However, I got another idea from this excel file with some modification
    http://www.ozgrid.com/FreeDownloads/PasswordBook.zip

    in this file, there is a sheet called "Config" that contents all user name & password.
    I would like to delete that sheet i.e. "Config" and keep two user names + password in the vba itself.

    meaning, I hope you modify this code for UserForm1

    Option Explicit
    
    Private Sub CancelButt_Click()
        ThisWorkbook.Close SaveChanges:=False
    End Sub
    
    Private Sub CommandButton1_Click()
        ThisWorkbook.Close SaveChanges:=False
    End Sub
    
    Private Sub OKButt_Click()
        Dim iFoundPass As Integer
        On Error Resume Next
        With Sheets("Config").Range("UserNames")
            iFoundPass = .Find(What:=UserNameTextBox, After:=.Cells(1, 1), LookIn:=xlValues,  LookAt:=xlWhole, _
            SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= False).Row
        End With
        On Error GoTo 0
        If iFoundPass = 0 Then
            SomethingWrong
            Exit Sub
        End If
        If Sheets("Config").Cells(iFoundPass, 2) <> PasswordTextBox Then
            SomethingWrong
            Exit Sub
        End If
        Sheets("Config").Range("LoggedInAs") = UserNameTextBox
        Unload Me
    End Sub
    
    Private Sub PasswordTextBox_Change()
        OKButt.Enabled = (UserNameTextBox.TextLength > 2 And _
        PasswordTextBox.TextLength > 2)
    End Sub
    
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
        If CloseMode = 0 Then Cancel = True
    End Sub
    
    Private Sub UserNameTextBox_Change()
        OKButt.Enabled = (UserNameTextBox.TextLength > 2 And _
        PasswordTextBox.TextLength > 2)
    End Sub
    
    Private Sub SomethingWrong()
        MsgBox "Incorrect Username or Password.", vbCritical + vbInformation, "OzGrid.com"
    End Sub


    VBA in ThisWorkbook, I modified it to become as follow:

    Option Explicit
    
    Private Sub Workbook_Open()
        Dim objNet As Object
        Dim i As Integer
        On Error Resume Next
        Set objNet = CreateObject("WScript.NetWork")
        'To select the first sheet
        For i = 1 To Worksheets.Count
            If Sheets(i).Visible Then
                Sheets(i).Select
                Exit For
            End If
        Next i
        If objNet.UserName <> "loveguy1977" Then
            Set objNet = Nothing
            Sheets("Config").Visible = xlVeryHidden
            Application.EnableCancelKey = xlDisabled
            UserForm1.Show
        End If
        Set objNet = Nothing
    End Sub

    Then I will protect each excel file's VBA with password.


    Thank you very much
    Last edited by Aussiebear; 12-11-2024 at 01:13 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •