I have a workbook that is designed to essentially operate as a standalone application. All sheets are protected, the individual excel tabs are hidden, and the top excel ribbon is hidden as well for the entire workbook.
The following VBA code performs the above procedures and is applied to every sheet within the workbook.
Sub masque()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
ActiveWindow.DisplayHeadings = False
ActiveWindow.DisplayGridlines = False
ActiveWindow.DisplayWorkbookTabs = False
Application.DisplayFullScreen = True
Application.DisplayStatusBar = Not Application.DisplayStatusBar
Application.WindowState = xlMaximized
ActiveWindow.WindowState = xlMaximized
Application.DisplayFormulaBar = False
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
I want to use the following code as a button to override the prior code in order for an individual to easily switch between an "editor" mode and "user mode"
Sub masteredit()
Application.ScreenUpdating = False
ActiveWindow.View = xlNormalView
ActiveWindow.DisplayHeadings = False
ActiveWindow.DisplayGridlines = False
ActiveWindow.DisplayWorkbookTabs = False
Application.DisplayStatusBar = False
ActiveWindow.DisplayHorizontalScrollBar = True
ActiveWindow.DisplayVerticalScrollBar = True
ActiveWindow.DisplayWorkbookTabs = True
Application.DisplayFullScreen = False
Application.DisplayFormulaBar = True
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
Application.ScreenUpdating = True
What is a good way to accomplish this?
well, you could have a predermined type of user, for example, by default the app will be for user_mode. So you use a special sub called auto_open(), that will be run each time you open the workbook. So we have
sub auto_open()
call masque
end sub
And you can add buttons whenever you want to change between editor mode and user mode. You can put sub auto_open() in any module you want, because it is detected as special by Vba
Solved the issue.
I forgot I had the following code on every sheet in the workbook.
Sub Worksheet_Open()
Call masque
End Sub
Sub Worksheet_Activate()
Application.ScreenUpdating = False
Call masque
Application.ScreenUpdating = True
End Sub
Therefore, any time I tried to navigate to a different sheet, the masque would be applied.
To solve my issue, I removed the prior code from every page. I then added a checkbox on my "Home" page that used the following code.
Sub Worksheet_Open()
Call masque
End Sub
Sub Worksheet_Activate()
Application.ScreenUpdating = False
Call masque
Application.ScreenUpdating = True
End Sub
This way, when you open up the workbook the masque is automatically applied. However when you click the checkbox you enter editor mode and the masteredit sub is applied. And when it is unchecked, the masque is once again applied.
Related
I have a macro that hides the ribbon, headings, tabs, scrollbar, etc. and a macro that unhides everything again. However, I'm having trouble with showing the Ribbon again. The following line does not work for me:
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
I've tried running the command in a separate macro, but I can't bring back the Ribbon again. I can't press CTRL + F1 and in the options menu the Ribbon section is completely empty. The only way to bring it back, is to open a new document, that seems to rest it. Does anyone know what could be wrong?
Sub UI()
Worksheets("MAIN").Activate
With ActiveWindow
.DisplayHeadings = False
.DisplayWorkbookTabs = False
.DisplayHorizontalScrollBar = False
.DisplayVerticalScrollBar = False
End With
With Application
.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
.DisplayStatusBar = False
.DisplayFormulaBar = False
End With
End Sub
Here is the macro that unhides everything
Sub UI_Reset()
Worksheets("MAIN").Activate
With ActiveWindow
.DisplayHeadings = True
.DisplayWorkbookTabs = True
.DisplayHorizontalScrollBar = True
.DisplayVerticalScrollBar = True
End With
With Application
.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
.DisplayStatusBar = True
.DisplayFormulaBar = True
End With
End Sub
so I tried the solutions here Excel ScreenUpdating False and still flickering screen but nth worked , im wondering if I should put the screen update in the fucntion I call
Note that the function i call is gonna call another that'll parse data in the sheet once button 2 is clicked,Here's the code I did so far
Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
ButtonOneClick = False
Call SheetName
If ButtonOneClick Then
Me.CommandButton2.Visible = True
Else
Me.CommandButton2.Visible = False
End If
Application.ScreenUpdating = True
End Sub
I have the following codes which is working for some people but not others.
The following does the reverse at opening the spreadsheet.
Could it be a setting it excel?
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Control As Office.CommandBarControl
Application.CommandBars("ply").Enabled = True 'disables right-Click on
sheet tab
For Each Control In Application.CommandBars.FindControls(ID:=21)
'disables CUT
Control.Enabled = True
Next Control For Each Control In
Application.CommandBars.FindControls(ID:=19) 'disables COPY
Control.Enabled = True
Next Control
Application.DisplayFormulaBar = True
Application.CutCopyMode = True
Application.CellDragAndDrop = True
End Sub
I am looking to disable zoom slider in excel worksheet. I have looked around but couldn't find a solution to it. There are some solutions pointing to setting the zoom to a defined value but none of them caters to disabling the zoom option itself.
Any help would be much appreciated.
I am adding the code I have put in ThisWorkbook to disable most of the visible option on worksheet.
Private Sub Workbook_Activate()
Application.ScreenUpdating = False
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
Application.DisplayFormulaBar = False
Application.DisplayStatusBar = Not Application.DisplayStatusBar
ActiveWindow.DisplayWorkbookTabs = False
Application.ScreenUpdating = True
End Sub
Private Sub Workbook_Deactivate()
Application.ScreenUpdating = False
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
Application.DisplayFormulaBar = True
Application.DisplayStatusBar = True
Application.ScreenUpdating = True
ActiveWindow.DisplayWorkbookTabs = True
End Sub
Private Sub Workbook_Open()
Application.ScreenUpdating = False
'Hide list of sheets
Call hide_sheets
Windows(1).WindowState = xlMaximized
ActiveWindow.DisplayGridlines = False
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)"
Application.DisplayFormulaBar = False
Application.DisplayStatusBar = Not Application.DisplayStatusBar
ActiveWindow.DisplayWorkbookTabs = False
ActiveWindow.Zoom = 100
'Lock cells in the UI sheet
ThisWorkbook.Sheets("UI").ScrollArea = "A1:t46"
'Hide scroll bar
With ActiveWindow
.DisplayHorizontalScrollBar = False
.DisplayVerticalScrollBar = False
End With
Application.ScreenUpdating = True
welcomeScreen.Show 0
End Sub
Some screen shots of the problem I am facing. I am currently using some makeshift arrangement by loading the maximized version userform on workbook opening. So the slider is hidden.
There doesn't appear to be a way to disable zoom completely or specifically the slider after looking around. If you're main mission is to avoid someone clicking on the zoom slider I would probably go with hiding the statusbar all together.
Application.DisplayStatusBar = False
To hide the zoom slider alone you can do so by editing the registry key
HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Excel\StatusBar
by setting ZoomSlider value to 0
Anyway, i don't think this can be achieved using VBA even with SaveSetting.
You can try write a .reg file to change the target key and VBA-load it. I'm not sure if this can be done but even if it works the user will still to have click Yes in a system prompt to allow the key to be loaded into registry.
And even when the user click Yes to allow the .reg file to load and change the registry key, Excel status bar doesn't refresh to show/hide the ZoomSlider, until Excel is restarted.
In short, hiding zoom slider alone using VBA doesn't seem to be achievable.
I have seen where you can run a macro based on inserted text, but the macro has to be embedded in the sheet, i.e., Private Sub Worksheet_Change(ByVal Target As Range).
What I want to do is call the macro from my add-in from a user's workbook that will not have "Worksheet_Change..." already embedded at the sheet level. Is there a way to do this?
As for additional background, I know I can run the macro from the add in, but I want to activate it using a bar-code scan rather than calling the macro from a button or some other interface.
My bar-code reads as Make Landscape 1 pg when scanned. Hoping to use some modification of this:
Private Sub Worksheet_Change(ByVal Target As Range)
If (Target.Value) = "Make Landscape 1 pg" Then
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
Application.ScreenUpdating = False
'ActiveWindow.SelectedSheets.PrintPreview
ActiveSheet.Select
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Application.ScreenUpdating = True
End If
End Sub
Here's a link that I found very useful when needing to access Worksheet/Workbook-level events via modules in my Add-In. The basic implementation is like so:
In Add-In's ThisWorkbook module:
Private WithEvents App As Application
Private Sub Workbook_Open()
Set App = Application
End Sub
Now App can be used to call/access workbook & worksheet events. If you're trying to check something upon selection change from a module in an add-in it has to be Workbook_Sheetselectionchange event (which you can read more about here) instead of the Worksheet_Change event. This event can be used in conjunction with the previously set App variable like so:
In Add-In's ThisWorkbook module:
Private Sub App_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Excel.Range)
If (Target.Value) = "Make Landscape 1 pg" Then
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
Application.ScreenUpdating = False
ActiveSheet.Select
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
Application.ScreenUpdating = True
End If
End Sub