0

I have searched from google but I still can't find a clear answer. I have written code in excel vba. -How to restrict the program users access to the code? Adding a password in VBA project properties is easy to crack so what is the best and easiest way to hide the vba code from program users?

Another post suggest VB6 but it's obsolete and I can't find where to download it.

The Access error message when trying to save in ACCDE. The Access error message when trying to save in ACCDE. Part 2

Community
  • 1
  • 1
Coldcode
  • 29
  • 9
  • 2
    Possible duplicate of [So my Excel-VBA project password can easily be cracked... What are other options?](http://stackoverflow.com/questions/1063155/so-my-excel-vba-project-password-can-easily-be-cracked-what-are-other-options), numerous others. – Comintern Jan 11 '17 at 22:26
  • The VB6 mentioned in the another post seems to be obsolete and I can't find where to download it. – Coldcode Jan 11 '17 at 22:44
  • Then check some of [these others](http://stackoverflow.com/search?q=%5Bexcel-vba%5D+project+password). Those run about 50-50 between cracking and preventing cracking. If you don't find anything there, [check these results](https://www.google.com/?gws_rd=ssl#q=excel+vba+project+prevent+password+cracking). – Comintern Jan 11 '17 at 22:49

1 Answers1

0

I have verified that it is possible to write VBA code in MS Access project, compile to an accde file. So after OP had some issue, editing this post to make my steps more explicit...

Create an Excel Workbook file which we will call back into because we want to prove we can interact with the Excel session. I called my workbook N:\WorkbookControlledByAccess.xlsm and in a module I wrote some code that can be called into using Application.Run This code is trivial but exemplary

Option Explicit

Public Function SomeExportedFunction() As String
    SomeExportedFunction = "Hello 47"
End Function

Then I opened MS Access and went File->New->Blank desktop database and pressed Create which accepted the given default database filename, for me 'Database5', this will create Database5.accdb. And the default window is a new Table, Table1, close that. On the ribbon, go Create->Blank Form.

On the Form create a command button, this throws an annoying wizard, cancel the wizard. Right-click newly created button to get context menu and then click Build Event, from the Choose Builder dialog choose Code Builder, this gives an error "To add a code module to a form or report, you must switch to Design view and set the HasNModule property of the form or report to Yes." Click OK to that error and switch to design view by using the View button on the Design ribbon. Once in design view try the context menu step again. You should get a VBA IDE window now which has the following code

Option Compare Database
Option Explicit

Private Sub Command0_Click()

End Sub

We will test the button by changing this to

Option Compare Database
Option Explicit

Private Sub Command0_Click()
    MsgBox "Just access at the moment"
End Sub

One runs the form by pressing F5, the form runs, click the button and our new message box appears. Ok, now to do some Excel Access interop. Add Tools->References and add Microsoft Excel 15.0 and change the code to be

Option Compare Database
Option Explicit

Public Sub Command0_Click()

    '* Use GetObject to verify the workbook is loaded and accessible via
    '* RunningObjectTable
    Dim wb As Excel.Workbook
    Set wb = GetObject("n:\WorkbookControlledByAccess.xlsm")

    '* If we got here without error then we should be able to call back into Excel session.
    MsgBox wb.Parent.Run("WorkbookControlledByAccess.xlsm!SomeExportedFunction")

    'MsgBox SomeExportedFunction
End Sub

Now if you run the form and click the button the message is retrieved from the Excel workbook we created earlier. So this proves Access can reach Excel.

That was in a normal accdb file and one needs to password protect the code.

Then when you want to create the accde file you go File->Save As->Make ACCDE and follow the file dialog. You can then open the accde file and the code will be locked.

I have yet to do exhaustive search for any hacks into an accde file yet but we know the standard Excel VBA is not safe.

S Meaden
  • 8,050
  • 3
  • 34
  • 65
  • I copied the working Excel VBA code. I went to Access visual basic editor, inserted a new module and pasted it. When I tried to save it in ACCDE it prompted and error saying Access was unable to create the .accde, .mde, or .ade file. This error is usually associated with compiling a large database into an MDE file. Because of the method used to compile the database aconsiderable number of TableID references are created for each table. etc. – Coldcode Jan 11 '17 at 23:34
  • I linked in my original post for the screenshots. – Coldcode Jan 11 '17 at 23:46
  • Have edited my answer to give explicit steps as to what I did. – S Meaden Jan 12 '17 at 00:11
  • I tried this but this need to be run in Access. Is it possible to run the code in Excel by clicking inserted button in Excel? My code (simplified) uses the A, B, C columns data to calculate new data to D, E, F columns. I want that the program user can click the inserted button in Excel to calculate the value for the new columns. But the program user should not see the code. – Coldcode Jan 12 '17 at 00:51
  • The code in Excel will not be protected. This is a question that has been raised many times. You can write in a different language if you like C#, VB.NET , C++ but VBA as housed in Excel workbook is not protected it is easily broken into. Sorry, you have to pick the least of evils here. – S Meaden Jan 12 '17 at 00:56
  • Which of those are easiest to write and what IDE should I use? In addition, if I write with one of those languages, does it provide the ability to use the button in Excel and other features like in the Excel VBA version of code? – Coldcode Jan 12 '17 at 01:06