Forum Discussion
Dashboard customization
Thank you so much.
I was able to hide the ribbon but I can't get them back, so I wonder what tabs are you making reference?
Thank you again.
For close with open file
Private Sub Workbook_Open()
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
End Sub
for open with closing file
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
End Sub
Insert this in ThisWorkbook and so you can have close the ribbon if you open the file and its is open again for the other files if you close the file.
- ADumithMay 31, 2023Iron Contributor
Hello NikolinoDE
I have gone a little further, and have managed to put together this little code, however for some unknown reason when I open the file the code does not execute.
I have enabled macro execution and it still does not work, any ideas?
Option Explicit Private Const Password As String = "My_Pass" Private Sub Workbook_Open() Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"", False)" For Each Sheet In Worksheets Sheet.Visible = xlSheetVeryHidden Next Sheet If Not Application.EnableEvents Then MsgBox "Macros are disabled. To enable the modification, activate the macros and reopen the file.", vbExclamation End If End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"", True)" End Sub Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) If Not CheckPassword() Then Cancel = True End If End Sub Private Function CheckPassword() As Boolean Dim userInput As String On Error Resume Next userInput = InputBox("Enter the password to enable modification:", "Password") If Err.Number <> 0 Then CheckPassword = False ElseIf userInput = Password Then CheckPassword = True Else MsgBox "Wrong password. Modification is not allowed.", vbCritical CheckPassword = False End If On Error GoTo 0 End FunctionThank you,
- NikolinoDEJun 01, 2023Platinum Contributor
The code you provided appears to be free of syntax errors. However, please note that without the full context and the specific requirements of your Excel workbook, it is difficult to determine if the code will function as intended. There could be several reasons why the code is not executing properly.
Here are a few things you can check:
- Macro Security Settings: Make sure that the macro security settings in Excel are not set to disable all macros. You can check this by going to the "File" menu, selecting "Options," then "Trust Center," and finally "Trust Center Settings." Under the "Macro Settings" category, choose the option that enables macros.
- Trusted Locations: Ensure that the location of the file is added to the trusted locations in Excel. This can also be found in the Trust Center settings mentioned above, under the "Trusted Locations" category.
- Trusted Documents: If the file was previously opened with macros disabled, Excel might have marked it as an untrusted document. In this case, you can try to remove the file from the "Trusted Documents" list. To do this, go to the Trust Center settings, select the "Trusted Documents" category, and remove the file from the list.
- Protected View: Check if the file is opening in "Protected View." In this mode, macros are disabled by default. You can see if the file is in protected view by looking for a yellow bar at the top of the Excel window. If the file is in protected view, you can click on the "Enable Editing" button to enable macros.
- Debugging: Add some debugging statements or breakpoints in your code to see if it is getting executed at all. For example, you can add MsgBox "Workbook_Open event triggered." at the beginning of the Workbook_Open sub to check if it runs when the file is opened.
By checking these points, you should be able to identify the issue preventing the code from executing properly.
- ADumithJun 01, 2023Iron Contributor
Hello NikolinoDE
I have placed this portion of the code in ThisWorkBook and it works, so I think is that somehow I am not invoking the module execution unless that is automatic.
Private Sub Workbook_Open() Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)" End SubLooking forward to hearing from you on this regard.
Thank you again,