How to Create Visual Basic Code with Personal Macro Book and Restrict Code Access

What is the personal macro book?

The personal macro book is a file hidden in a path on your PC. It is the file that is created the first time you create a macro and save it in your personal macro folder. The specific path where it is saved is as follows:

C: Users Username AppData Roaming Microsoft Excel PERSONAL.XLSB

Folder AppData is hidden inside the system, you need to enable the Show hidden files and folders option to access your personal macro book location. To access your personal macro book and view macros, access Visual Basic from the Excel application from the Developer tab.




Once inside the Visual Basic application you can find your personal macro book in the VBAProject panel with the name VBAProject (PERSONAL.XLSB). Inside the Modules folder are the saved macros. The forms saved here are available for any Excel file.

How to create Visual Basic code with personal macro book?

From the modules folder you can delete macros or even create new ones using Visual Basic code. If you are an advanced Excel user you should be familiar with the code syntax.

Final report: if you want to delete a code, just right click on it and select the Remove module option.

The first thing to keep in mind is the programming language Visual Basic is object oriented and each Excel element is represented in VBA as an object. Each object has its respective properties and objects that define how the object looks and behaves,

Create a macro by code

To create the first macro by code within the Visual Basic application, click the option Inserisci and then click Module.




How to Create Visual Basic Code with Personal Macro Book and Restrict Code Access

A new module is created in the folder VBAProject (PERSONAL.XLSB). The section to the right of the application where the code appears appears as a blank area for adding the first module instructions. Write the following routine to create your first macro via code.

Sub macroporcode ()
         MgBox "My first code macro"
End Sub

The code above shows the name assigned to the macro which is “macro code”. Every subroutine or macro you create must have a beginning and an end. L' End Sub represents the end of the macro execution. The subroutine are used for group code statements. the correct way to start it, which is the abbreviation Sub, followed by the name and parentheses.


The user is shown a message with the MsgBox function. There function MsgBox it is one of the most used in VBA to send messages to the user. The code of this routine is simple, it only sends a message that appears on the screen with the accept button that is added by default.


Try the macro

How to Create Visual Basic Code with Personal Macro Book and Restrict Code Access

To check the operation of the macro, simply click on the button Run or press F5. If there are no errors of any kind, the routine that should execute the macro starts running to the end.


Restrict access to the code

Within your Visual Basic application you can protect with password the your code from macros.

  • Right-click the project and select the option Property project VBA. ..
  • Click on Security tab.
  • Enable the option Lock project for viewing.
  • Enter your password to view the properties of the project.
  • Confirm the password and press the accept button to save the changes.
add a comment of How to Create Visual Basic Code with Personal Macro Book and Restrict Code Access
Comment sent successfully! We will review it in the next few hours.