Enable The Macros & VBA Project From Excel Option Through VB Code
Enable The Macros & VBA Project From Excel Option Through VB Code
Need help to Enable The Macros & VBA Project From Excel Option Through VB Code. I' have created an excel file which contains the Macros and VB codes in which I' have kept some restriction while using the file, but the user can still do the modification with disabling Macros.
Looking for a solution which will automatically enable the Macros and VB Code when the file is open, also the user should get the disable option deactivated while using that particular workbook.
Creators of macro viruses would love to be able to do that!
There is no way to force macros to be enabled.
As an alternative, you could make all sheets except a title sheet "Very hidden" so that they can only be unhidden using VBA, place code in the Workbook_Open event to unhide them and code in the Workbook_BeforeSave event to hide them again. When the user opens the workbook with macros disabled, it will be useless.
ou could use code like this. The workbook contains two sheets whose code names have been changed to Info and Data. Info will always be visible, but Data will only be displayed if macros are enabled.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Info.Select
Data.Visible = xlSheetVeryHidden
End Sub
Private Sub Workbook_Open()
Data.Visible = xlSheetVisible
Data.Select
End Sub
If you protect the VBA code in the workbook with a password, the end user won't be able to view the code or to unhide the hidden data sheet.
I have uploaded a sample workbook (zipped) to SkyDrive: http-://sdrv.-ms/WTgWWN
Download the zip file and extract the workbook to your hard disk.
By default, macros should be disabled, and you should see only the Info sheet.
If you enable macros, the Data sheet should be displayed.
The VBA code has been protected with the password Excel (this is case sensitive).