followed your instruction but still face to error Unexpected error (40230). Can i send email to you?
send me the file, i will make it password free. email@example.com
I was getting the error (40230) There wasn't a check in the lock project for viewing so I typed in a password and confirmed then the error went away and I was able to open all the files in the VBA without error. Thanks again for the information on un-locking the VBA.
I didn't write this code, but I have tested it and written what I hope are clear instructions on how to get through the process. It worked for me on an old project I couldn't remember my password to. Hope it works for others. How to unlock a VBA project if you lost the password: (.xlsm) How it works 1. Excel will call a system function to create the password dialog box. 2. If user enters the right password and click OK, this function returns 1. If user enters the wrong password or click Cancel, this function returns 0. 3. After the dialog box is closed, Excel checks the returned value of the system function 4. if this value is 1, Excel will "think" that the password is right, hence the locked VBA project will be opened. 5. The code below swaps the memory of the original function used to display the password dialog with a user defined function that will return 1 when being called. using the code 1. Open the file(s) that contain your locked VBA Projects (We will call this the DESIRED file for clarity) 2. Create a new xlsm file, by clicking “FILE” on Excel menu and select ing “NEW” – “Blank Workbook”, then from the FILE menu select “SAVE AS” and change the “Save as type:” to “Excel Enabled Macro Workbook” (doesn’t matter what you call the file, the default of “Bookx” is fine) then click “Save”. (We will call this the TEMP file for clarity) 3. In the TEMP file, open the Developer tab and select “Insert” and insert a Module. Block and copy the code below into Module1 of the TEMP file. ‘(code credited to Siwtom (nick name), a Vietnamese developer) Option Explicit Private Const PAGE_EXECUTE_READWRITE = &H40 Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" _ (Destination As Long, Source As Long, ByVal Length As Long) Private Declare Function VirtualProtect Lib "kernel32" (lpAddress As Long, _ ByVal dwSize As Long, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long Private Declare Function GetModuleHandleA Lib "kernel32" (ByVal lpModuleName As String) As Long Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _ ByVal lpProcName As String) As Long Private Declare Function DialogBoxParam Lib "user32" Alias "DialogBoxParamA" (ByVal hInstance As Long, _ ByVal pTemplateName As Long, ByVal hWndParent As Long, _ ByVal lpDialogFunc As Long, ByVal dwInitParam As Long) As Integer Dim HookBytes(0 To 5) As Byte Dim OriginBytes(0 To 5) As Byte Dim pFunc As Long Dim Flag As Boolean Private Function GetPtr(ByVal Value As Long) As Long 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 Long Dim OriginProtect As Long 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 Long, _ ByVal pTemplateName As Long, ByVal hWndParent As Long, _ ByVal lpDialogFunc As Long, ByVal dwInitParam As Long) As Integer If pTemplateName = 4070 Then MyDialogBoxParam = 1 Else RecoverBytes MyDialogBoxParam = DialogBoxParam(hInstance, pTemplateName, _ hWndParent, lpDialogFunc, dwInitParam) Hook End If End Function 4. Insert another Module in the TEMP file project and paste the code below in Module2 Sub unprotected() If Hook Then MsgBox "VBA Project is unprotected!", vbInformation, "*****" End If End Sub 5. Run the code by pressing the run icon ( ) 6. You should see a message that the project is now unlocked. 7. Come back to your VBA Projects. 8. Right click on the VBA project for the DESIRED file, Select PROPERTIES, open PROTECTION tab, then uncheck “Lock project for viewing” and press OK. 9. Save the DESIRED XLSM file and Close both files including the temp file you made. 10. Re-Open the DESIRED XLSM file and proceed to edit/view the VBA project macros now that the password is removed.
Hi, I need option for release the password from VBA word template (*.dot)
When I open the .xlsm in 7zip, there is no vbaproject.bas file, only vbaproject.bin. I tried opening this in Hexedit and searching for "VBP=" but it did not exist in the file.
I get the same result as sleepy08 7w. I also purchased a VBA password removal tool, and my result was "Document does not contain VBA passwords," even though my document asks me for a password when I open the VBA project. I'm completely stuck.
The solution from donaldgulledge worked a champ after reformatting the code in the editor.
Worked for me. Thanks a lot!
*Awesome*, first try and it worked. If you get this popup _"Unexpected error (40230)"_, just *click OK (6 or 7 times)* until it goes away. Then you open the vba editor.
Hola, muchas gracias por el tutorial, me ha servido mucho.
I didn't have the .bas file as well, but used the .bin file and in HexEdit searched for "DPB=", changed it to "DPx=" saved and moved the file back into the .xlsm file Opened it up, got lots of errors, just Ok them. Did the remaining portion, about removing protection. closed and reopened the file, and abracadabra NO PASSWORD REQUIRED!!! Thank you so much for this, saved my a$$.
how to open background file in vba project file
this works, Method 1 works, extract vba.bin file and edit it, put it back into the 7zip file., save and close. open excel file, directly press ALT+F11, it will throw errors, just click ok and viola its unlocked!
For XLSM files: 12. Right click on the VBA project, select properties. Open the Protection tab then check again "Lock project for viewing" with any password. Press OK. Save. Close/open.
Hi, I just do like that, but Fail. Can you help me by file attatch https://drive.google.com/file/d/1wR7AL26DRrXkaXnnTV8Ohgev5MasWzGl/view?usp=sharing
I am unable save HEX Edit once I change from DPB to DPx
worked for me
> @rameshbabu > DPB Use "notepade++"
Did work, but I used Notepad. All the macros disapeared, so I had to copy all the macros from other workbook. Thanks.