Accessing Password Protected Excel VBA

In a recent assignment at my office last week, I came across a situation where I had to make some changes in the VBA code of an excel document. The excel document was something getting used from long time and there was no one having details related to password through which VBA code in that document was protected. Also there was no related supporting document available. I was in a situation where I required getting the access of VBA code without password.

After a lot of search on web and spending quite some time, I was able to access the VBA code without knowing the password. Although there are a lot of information already available on web related to the topic, however most of the information are either in bits and pieces or not very simple to understand for a non techie person.

Hence I decided to write this blog to present the information in simplest manner possible. Give it a try if you are in similar situation and I am sure this is going to work for you as well. Please follow all steps precisely as mentioned.

Before we jump into steps to access the password protected VBA, it make sense to understand how it works. When we try to access password protected VBA document, the VBE (Visual Basic Editor) will call in build system function to create the password dialogue box. This dialogue box is where the user will enter password to access the document and will click on OK. If the user enters correct password and press OK, the system function will return 1. If the user enters incorrect password or click cancel, the system function will return 0. After the dialogue box is closed, the Visual Basic Editor (VBE) will check the value entered. If the value is 1, VBE will think that the password is right and will open the document. On the other hand, if the value is 0, VBE will think that password is incorrect and will not allow access to the document. The trick that we are going to use is basically to swap the value of 0 to 1 by using a code that can be written easily or can be taken from this post and included in your excel document. Hope this basic helps in making the concept a little easier. Lets jump into the steps now.

For the ease of understanding, I have created a sample VBA document called “Password_Test”. As you can see below, when I try to open this VBAProject, it prompts for a password to be entered.

Okay, so now we will go to the steps directly.

Step 1: First step first. make sure you take a backup of your original file and keep it at a different location in your PC or Laptop so that if accidentally we corrupt the file then we have a backup readily available.

Step 2: Create a new file with .xlsm extension.

An XLSM file is a macro-enabled spreadsheet created by Microsoft Excel, a widely used spreadsheet program that comes with every edition of the Microsoft Office suite.

For ease of understanding, I have named this file as “macro.xlsm”. To create this file, open MS Excel application and then go to File->SaveAs->location and then name your file as macro.xlsm. You can also choose file type from drop down.

Step 3: Open you locked VBA project file. In our case, its “Password_Test”.

Step 4: Open the new blank file that we just created. In our case its “macro.xlsm”

Step 5: We need to insert certain code in our new created “macro.xlsm” file. Once the file is open, click “ctrl+F11” to open the Visual Basic Editor. Once your VBE is open, you will see a screen like this.

Step 6: Select VBAProject (macro.xlsm) then go to Insert and click on Module. A blank page will open on right panel of the VB Editor.

Step 7: On the blank page that open on right of VBE, copy and paste below mentioned code:

Option Explicit

Private Const PAGE_EXECUTE_READWRITE = &H40

Private Declare PtrSafe Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As LongPtr, Source As LongPtr, ByVal Length As LongPtr)

Private Declare PtrSafe Function VirtualProtect Lib "kernel32" (lpAddress As LongPtr, _
ByVal dwSize As LongPtr, ByVal flNewProtect As LongPtr, lpflOldProtect As LongPtr) As LongPtr

Private Declare PtrSafe Function GetModuleHandleA Lib "kernel32" (ByVal lpModuleName As String) As LongPtr

Private Declare PtrSafe Function GetProcAddress Lib "kernel32" (ByVal hModule As LongPtr, _
ByVal lpProcName As String) As LongPtr

Private Declare PtrSafe Function DialogBoxParam Lib "user32" Alias "DialogBoxParamA" (ByVal hInstance As LongPtr, _
ByVal pTemplateName As LongPtr, ByVal hWndParent As LongPtr, _
ByVal lpDialogFunc As LongPtr, ByVal dwInitParam As LongPtr) As Integer

Dim HookBytes(0 To 5) As Byte
Dim OriginBytes(0 To 5) As Byte
Dim pFunc As LongPtr
Dim Flag As Boolean

Private Function GetPtr(ByVal Value As LongPtr) As LongPtr
    GetPtr = Value
End Function

Public Sub RecoverBytes()
    If Flag Then MoveMemory ByVal pFunc, ByVal VarPtr(OriginBytes(0)), 6
End Sub

Public Function Hook() As Boolean
    Dim TmpBytes(0 To 5) As Byte
    Dim p As LongPtr
    Dim OriginProtect As LongPtr

    Hook = False

    pFunc = GetProcAddress(GetModuleHandleA("user32.dll"), "DialogBoxParamA")


    If VirtualProtect(ByVal pFunc, 6, PAGE_EXECUTE_READWRITE, OriginProtect) <> 0 Then

        MoveMemory ByVal VarPtr(TmpBytes(0)), ByVal pFunc, 6
        If TmpBytes(0) <> &H68 Then

            MoveMemory ByVal VarPtr(OriginBytes(0)), ByVal pFunc, 6

            p = GetPtr(AddressOf MyDialogBoxParam)

            HookBytes(0) = &H68
            MoveMemory ByVal VarPtr(HookBytes(1)), ByVal VarPtr(p), 4
            HookBytes(5) = &HC3

            MoveMemory ByVal pFunc, ByVal VarPtr(HookBytes(0)), 6
            Flag = True
            Hook = True
        End If
    End If
End Function

Private Function MyDialogBoxParam(ByVal hInstance As LongPtr, _
ByVal pTemplateName As LongPtr, ByVal hWndParent As LongPtr, _
ByVal lpDialogFunc As LongPtr, ByVal dwInitParam As LongPtr) As Integer

    If pTemplateName = 4070 Then
        MyDialogBoxParam = 1
    Else
        RecoverBytes
        MyDialogBoxParam = DialogBoxParam(hInstance, pTemplateName, _
                   hWndParent, lpDialogFunc, dwInitParam)
        Hook
    End If
End Function

Step 8: Repeat Step 6 and 7 and paste following code in “Module 2”

Sub unprotected()
    If Hook Then
        MsgBox "VBA Project is unprotected!", vbInformation, "*****"
    End If
End Sub

Step 9: We are almost done. Next you need to run your code. To run the code, click on small Play button on the menu bar on top

You will see a message like this. Click on “OK” and your locked VBA project will be accessible now. Please note: This trick will work on 64 bit MS Excel only.

How to share screen without installing any software

If we want to share our screen for work or school related presentation, we require a specialized software to share the screen. Most of the organizations and school already have licenced tool available for this purpose. Most of the screen sharing tools requires an advance preparation before you can start. For example, the software must be downloaded, installed, configured and registered before you can actually start using the same. In some organizations, access to these tools are restricted to higher management only. Forget about organization, in our day to day life we often require sharing screen with a friend or group of people when we look for a quick solution rather than going for a licenced tool.

We will look at some of the fastest screen sharing website/tools that can be setup and be ready to use in couple of clicks. Lets have a look.

  1. Dead Simple Screen Sharing – I have kept Dead Simple Screen Sharing on top of our list because it is one of the simplest way to share the screen. One can access their website by following url https://deadsimplescreensharing.com/ Dead Simple Screen sharing supports audio/video right from your browser.

How to share screen using Dead Simple Screen Sharing

Step 1: Click the ‘Share your Screen Now’ button to create the screen sharing session and click on the “Allow Microphone”

Step 2: Install the chrome extension by clicking the install extension button. Extension is only required on Google Chrome, in Firefox you can do screen sharing without the extension

Step 3: A popup will appear that will ask you to select the screen you want to share. You can share your entire screen or an application window.

Step 4: Your screen is now being shared, you can invite participants by sharing the ‘Invite URL’ or using email

2. Web Whiteboard – Although, this is not a screen sharing tool however it is considered one of the simplest and easy to use Whiteboard to draw and write together online instantly. There is no installation or tutorial required to get started with Web Whiteboard. Passwords and accounts are entirely optional. Just create an online whiteboard with one click, and share it live by sending the link to people.

How to use Web Whiteboard

Step 1: Access Web Whiteboard by opening following URL in to your browser: https://www.webwhiteboard.com/

Step 2: You will get option to either Signup, login or Create free whiteboard. Select as per your requirement.

Step 3: If you opt to signup, the cost is $8 per month. However if you go for a free Whiteboard, it will last for 21 days.

Step 4: Once your free whiteboard is ready, you can share the URL at the top of your browser to other people you want to join you. The URL will look somewhat like https://www.webwhiteboard.com/board/vh33myar

Step 5: The whiteboard can be accessed from any browser in PC, Laptop, Tablets or Mobile phones.

3. HelloAiko Meet – This is again a simple and free tool preferred for video conferencing. The tool is free forever and do not require you to provide any credit card details. ‘Aiko Meet’ adds the power of cutting-edge Artificial Intelligent to a convenient, browser based video conferencing solution. Aiko Meet works entirely in your browser, without any extensions or installations. Aiko Meet uses TLS, the current standard in secure communications, to ensure that your conversations remain totally private

How to use Hello Aiko Meet

Step 1: Access ‘Hello Aiko Meet’ by typing following URL into your browser: https://helloaiko.com/meet

Step 2: On the page that opens, click on ‘Get Started’

Step 3: If you are a new user, you need to create a one time login account by clicking on “Signup” button and providing a user name and password. If you are an existing user, you use to “Signin” at the top right of the page.

When you signup for the first time, a room is also created for you that can be used for video conferencing services.

Step 4: Once you are login and ready, on the left hand side menu, you get options like ‘Add a Team Member’, ‘Integration with your domain’, ‘Settings’ etc.

Step 5: On the top left, there is an option to go to room. Once you click on this button, you can enter the Video Conferencing Room dedicated for you. Once inside your room, you will also get a link to your room that you can share with your participants. When a participant joins in, You receive a notification to accept or reject the request.

Step 6: on the bottom of your meeting room, you see several controls like mute/un-mute microphone, stop/start your video, share your screen, chat window etc.

Finally, hope these three free tools will definitely going to help you in your day to day work. Feel free to share your experience about the same and comment on the post.