VBA code asking for Macro

KMH

New Member
Joined
Nov 10, 2022
Messages
23
Office Version
  1. 2013
Platform
  1. Windows
I placed in this code in ThisWorkbook in an attempt to have it remove all Toolbars and Menus from Sheet2 only, but it's triggering the Macro Name prompt. How do I fix that. It's just supposed to run automatically without a Macro. There is also a bit of code above that to allow the Macro buttons on the other sheets to work when the worksheet is protected. The bit I need sorted out is the one that starts with - Private Sub Workbook_SheetActivate(ByVal Sh As Object)

I should also point out that Sheet2 is named COVER. Should I be referring to Sheet2 or COVER in the code?

VBA Code:
Private Sub Workbook_Open()

Call AllowMacroWhenProtected

End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)

Dim ws As Worksheet

If ActiveSheet.Name = "Sheet2" Then
Application.CommandBars("Worksheet Menu Bar").Enabled = False
Application.CommandBars("Standard").Visible = False
Application.CommandBars("Formatting").Visible = False
Application.CommandBars("Custom 1").Visible = False
With ActiveWindow
        .DisplayHorizontalScrollBar = False
        .DisplayVerticalScrollBar = False
    End With
Application.DisplayFormulaBar = False
Application.DisplayStatusBar = False
Else
Application.CommandBars("Worksheet Menu Bar").Enabled = True
Application.CommandBars("Standard").Visible = True
Application.CommandBars("Formatting").Visible = True
Application.CommandBars("Custom 1").Visible = True
With ActiveWindow
        .DisplayHorizontalScrollBar = True
        .DisplayVerticalScrollBar = True
    End With
Application.DisplayFormulaBar = True
Application.DisplayStatusBar = True
End If
 
Application.DisplayAlerts = True
End Sub



Many thanks in advance for your help!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Why not simply put it this into the "COVER" sheet module.
VBA Code:
Private Sub Worksheet_Activate()
Dim ws As Worksheet
If ActiveSheet.Name = "COVER" Then.........the rest of the code
 
Upvote 0
I've attached a picture of my screen, if that helps any
 

Attachments

  • Screenshot of VBA Code.png
    Screenshot of VBA Code.png
    94 KB · Views: 13
Upvote 0
Why not simply put it this into the "COVER" sheet module.
VBA Code:
Private Sub Worksheet_Activate()
Dim ws As Worksheet
If ActiveSheet.Name = "COVER" Then.........the rest of the code
Changed the name of the worksheet from Sheet2 to COVER as suggested, and got this error:

1689313206015.png
 
Upvote 0
did you move it to the sheet module ??
 
Upvote 0
It needs to be in the sheet module so that when the sheet is activated, to code will run
 
Upvote 0
It needs to be in the sheet module so that when the sheet is activated, to code will run
I moved it to the Sheet2 (COVER) and still got the error:

1689314918849.png


I clicked to debug it, and this is the line highlighted:

1689314981823.png
 
Upvote 0
Check to make sure the CommandBar is called "Custom 1"
I think it will either need an underscore OR No space
So, either "Custom_1" OR "Custom1"
 
Upvote 0
Thanks for your time and energy with that, but nothing I try is working. Is there an easier way to make the entire workbook show in full screen but still see the worksheet tabs?
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top