Results 1 to 5 of 5

Thread: Protect vba project from hacking (Here is a FREE solution)

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2023
    Posts
    7

    Protect vba project from hacking (Here is a FREE solution)

    You can manage the Excel file via VB programmatically but it can take several minutes when the Excel file is big considerably. On the other hand, VBA-userform can perform the same function very very fast. That's why, I am presenting this secure idea to use VBA-userform.

    In this method, the VBA userform files (.frm and .frx) will be saved in a password-protected zip file. No one will be able to unzip the file that is the actual security.

    This method involves to import the VBA-userform from a password-protected zip file and run the subroutines in VBA-userform programmatically. The VBA-userform will be removed from the Excel file after running a subroutine.

    Unzipping the file and importing the VBA-userform will take a few seconds whenever you need to run any subroutine in VBA-userform. So, this process is not an issue in any way.

    The following code will run in VB6 or VB.Net form because you can distribute the VB form commercially with secure password protection. Here are the steps:

    Please comment, if there is any vulnerable or insecure point and how to improve it.

    Code:
    Dim xlApp As Excel.Application
    Dim xlWorkbook As Excel.Workbook
    Dim vbComponent As Object
    
    ' Create an instance of Excel Application
    Set xlApp = New Excel.Application
    
    ' Open the destination workbook
    Set xlWorkbook = xlApp.Workbooks.Open("destination_workbook.xlsm")
    
    'Unzip .frm and .frx files from a password-protected Zip file
    
    ' Copy the UserForm from the source to destination
    xlWorkbook.VBProject.VBComponents.Import "C:\Temp\UserFormName.frm"
    
    'Delete the .frm and .frx files
    
    'Save the input values to the registry
    
    'VBA userform will get the inputs to  from the registry
    
    ' Show the UserForm and run the associated subroutine
    xlApp.Run "YourUserFormName.YourSubroutineName"
    
    'Userform will write to registry when a process is complete
    
    'the VB form will keep checking the registry value, when found, then VB form will show "Complete" message
    
    'Remove the userform 
    Set vbComponent = xlWorkbook.VBProject.VBComponents("UserFormName")
    xlWorkbook.VBProject.VBComponents.Remove vbComponent
    
    ' Close workbooks without saving changes (for example purposes)
    xlWorkbook.Close SaveChanges:=False
    
    ' Quit Excel
    xlApp.Quit
    
    ' Clean up
    Set xlWorkbook = Nothing
    Set xlApp = Nothing
    Last edited by asad523r357564; Dec 3rd, 2023 at 04:10 AM.

  2. #2
    Fanatic Member
    Join Date
    Mar 2023
    Posts
    724

    Re: Protect vba project from hacking (Here is a FREE solution)

    This meens I need to have Excel or Office scripting library installed to have use of it?

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,629

    Re: Protect vba project from hacking (Here is a FREE solution)

    Why not store a hash of the passwords in some database? If you use a SQL server, that'll be extremely secure (unlike MS Office's "soft" security).

    Heck, you could even use an MDB file with security, and that'd be about as secure as Excel, and you wouldn't need anything extra on your computer (as you don't need MS-Access to read/write an MDB file from VB6).

    -------

    Also, notice I said "hash of the password". AFAIK, most modern password schemes don't even store the actual password anywhere. Rather, they store a one-way hash of it. What this means is, if someone gets those hash codes (by hacking whatever security is protecting them), they still don't have the passwords.

    You may ask: If I don't save the passwords, how do I check that someone typed in the correct password? That's easy ... "hash" the password they typed in, and then compare it to their saved hashed password. If the two hashes match, they typed in the correct password. Just use a hash algorithm that is "hard to reverse" of which there are many.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2023
    Posts
    7

    Re: Protect vba project from hacking (Here is a FREE solution)

    Yes, of course, using SQL server or MDB file is very much secure.

    Actually, I have written already most of program in VBA and now I do not want to reprogram the entire application.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2023
    Posts
    7

    Re: Protect vba project from hacking (Here is a FREE solution)

    I tested the codes and I made some changes.

    First, set the Excel macro setting to "Disable all macros with notification". Create a button in Sheet and write this code "Shell "Path to your Vb6 .exe application", vbNormalFocus". Create a module "Module1". Save and close the workbook.

    Next time click "Yes" to macro-setting box when opening your workbook again.

    Here are the updated and tested codes:

    Code:
    Dim xlApp As Object
    Dim xlWorkbook As Object
    Dim vbComponent As Object
    Dim xlModule As Object
    
    ' Create an instance of Excel Application
    Set xlApp = New Excel.Application
    
    ' Reference to already opened workbook
    Set xlApp = GetObject(, "Excel.Application")
    Set xlWorkbook = xlApp.Workbooks("WorkbookName")
    Set xlModule = xlWorkbook.VBProject.VBComponents("Module1")
    
    'Unzip .frm and .frx files from a password-protected Zip file
    
    ' Import userform
    xlWorkbook.VBProject.VBComponents.Import "Path to userform"
    
    'Delete the .frm and .frx files
    
    'Save the input values to the registry
    
    'VBA userform will get the input values from the registry
    
    ' Run the subroutine from Module1
    xlApp.Run "YourMacroName"
    
    'Userform will write to registry when a process is complete
    
    'the VB form will keep checking the registry value, when found, then VB form will show "Complete" message
    
    'Remove the userform 
    Set vbComponent = xlWorkbook.VBProject.VBComponents("UserFormTest")
    xlWorkbook.VBProject.VBComponents.Remove vbComponent
    
    ' Clean up
    Set vbComponent = Nothing
    Set xlModule = Nothing
    Set xlWorkbook = Nothing
    Set xlApp = Application
    The subroutine in Module1 should have the following codes:

    Code:
    Sub YourMacroName()
    Call UserForm.Test 'Test subroutine in Userform must be Public (not Private)
    End Sub
    The button on Excel sheet will open your VB6 or VB.Net application. The subroutine of Userform will be called from Module1. This way your entire userform will keep untouched and unaccesable.
    Last edited by asad523r357564; Dec 10th, 2023 at 04:48 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width