ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macros (https://www.excelbanter.com/excel-programming/377838-macros.html)

[email protected]

Macros
 
Forgive me if my questions is too basic but I am not a developer. I
would like to know if there is nayway that I can have an excel sheet
close out if macros are not enabled? If not, is there a way to make
sheets not visible if Macros are not enabled? Thanks for any help


Sandy

Macros
 
If you are refering to the enable or disable macros message box when a
workbook opens than no, as far as my knowledge of vba goes. When you
open a workbook and the user disables macros then any macros in that
workbook will not execute, so any code to hide a sheet or close a
workbook will not run.

Sandy


wrote:
Forgive me if my questions is too basic but I am not a developer. I
would like to know if there is nayway that I can have an excel sheet
close out if macros are not enabled? If not, is there a way to make
sheets not visible if Macros are not enabled? Thanks for any help



Sandy

Macros
 
If you are refering to the enable or disable macros message box when a
workbook opens than no, as far as my knowledge of vba goes. When you
open a workbook and the user disables macros then any macros in that
workbook will not execute, so any code to hide a sheet or close a
workbook will not run.

In order to work around this will take some coding in a specific area.
You'll need to hide all your sheets that you don't want visible if the
user doesn't enable macros in the Workbook_BeforeClose event, and
you'll need to write the Workbook_Open event that will make the
previous sheets visible. Now this alone will work, but if any
intermediate excel user knows there way around excel they could just
manually unhide the sheets after denying the macros from running, so
you'll have to disable the sheets menu on the format dropdown and add
it to the Workbook_BeforeClose event. Below is the different bits of
code to get this to work.


Open VBE (Alt + F11)
Open Project explorer (Ctrl + r)
Double click on ThisWorkbook under your workbook and paste the code
below

'Hides Sheet1 and Sheeet2 and disables the format-sheet menu
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Worksheets("Sheet1").Visible = False
Worksheets("Sheet2").Visible = False
Application.CommandBars("Worksheet Menu Bar") _
..Controls("Format").Controls("Sheet").Enabled = False
ActiveWorkbook.Save
End Sub

'Un-hides the sheets and enables the format-sheet menu
Private Sub Workbook_Open()
Worksheets("Sheet1").Visible = True
Worksheets("Sheet2").Visible = True
Application.CommandBars("Worksheet Menu Bar") _
..Controls("Format").Controls("Sheet").Enabled = True
End Sub


HTH & let me know how it worked out...

Sandy





wrote:
Forgive me if my questions is too basic but I am not a developer. I
would like to know if there is nayway that I can have an excel sheet
close out if macros are not enabled? If not, is there a way to make
sheets not visible if Macros are not enabled? Thanks for any help




All times are GMT +1. The time now is 08:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com