how to disable zoom slider through excel vba? - excel

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.

Related

Excel VBA Open Macro

The Excel VBA code below executes when I open my Excel document on my computer. However, when someone else opens my document, the code does not execute (VBA macros are enabled). I am also having the same issue with the custom ribbon I designed for the Excel document. When I open my Excel document on my computer the custom ribbon appears. However, when someone else opens my document, the custom ribbon does not appear.
Private Sub Workbook_Open()
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
.WindowState = xlNormal
.CommandBars("Full Screen").Visible = False
.CommandBars("Worksheet Menu Bar").Enabled = False
.DisplayStatusBar = False
.DisplayFormulaBar = False
.Width = 845
.Height = 408
End With
With ActiveWindow
.DisplayRuler = False
.DisplayHeadings = False
End With
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub
Could someone please explain to me how I could fix this ongoing issue. I don't understand why the Excel workbook formating is different between my computer and my colleagues computer.
Thank you!

VBA - Application.ExecuteExcel4Macro "show.toolbar(""Ribbon"",True)" not working

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

Rerun a macro when a combobox value in a userform is changed

I have a userform with a combobox to select the training type for various employee classes.
When the user selects one of the options from the dropdown menu it runs the macro below.
Private Sub TrainingType_Selection_Change()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
Dim TrainingType_Selection As String
TrainingType_Selection = Hiring_Validation_Form.TrainingType_Selection.Value
If TrainingType_Selection = "Sustain - 30" Or TrainingType_Selection = "Sustain - 60" Then
Hiring_Validation_Form.LinkingECPID_Selection.Visible = True
Hiring_Validation_Form.LinkingECP_Label.Visible = True
End If
If TrainingType_Selection <> "New Hire" Then
Hiring_Validation_Form.ReqReasonLv1_Selection.Visible = False
Hiring_Validation_Form.Label6.Visible = False
Hiring_Validation_Form.ReqReasonLv2_Selection.Visible = False
Hiring_Validation_Form.Label11.Visible = False
End If
End Sub
The problem I'm running into is that if someone makes a selection from the drop-down menu and then changes their mind and selects another value from the drop-down menu it isn't re-running the macro. For example they change it from the above "New Hire" to "Sustain - 30". I have a clear button on the userform, but that clears the entire form which would not be ideal in a situation where the user only wants to change one input, not completely start over.
How do I get the TrainingType_Selection_Change() macro to re-run again when the combobox selection is changed
This line:
Application.ScreenUpdating = False
disables screen updates even after the macro has finished running.
Add
Application.ScreenUpdating = True
as the last line before End Sub to re-enable them.
I was able to figure out a way to address this issue by using AfterUpdate()
I added the below macro and it now updates the entire form when selections are changed.
Private Sub TrainingType_Selection_AfterUpdate()
TrainingType_Selection = Hiring_Validation_Form.TrainingType_Selection.Value
Hiring_Validation_Form.LinkingECPID_Selection.Visible = False
Hiring_Validation_Form.LinkingECP_Label.Visible = False
Hiring_Validation_Form.ReqReasonLv1_Selection.Visible = True
Hiring_Validation_Form.Label6.Visible = True
Hiring_Validation_Form.ReqReasonLv2_Selection.Visible = True
Hiring_Validation_Form.Label11.Visible = True
Hiring_Validation_Form.Label21.Visible = True
Hiring_Validation_Form.NewHireSup_Selection.Visible = True
Call TrainingType_Selection_Change
End Sub

My pages load slowly. Code needs to be faster any suggestions?

Background: This project is gets loaded into full screen maximized.To make it look good I took out the tabs, formula bar, headers and status bar. I created my own buttons customized from shapes. These do have some very attractive colors and 3D views and I am wondering it is my code or the shapes that cause it to load slowly. When I Click a button to change pages is when this happens. Initially I had the button macros simply changing the pages but I thought it was slow because i was using select code. worksheet.Activate and worksheets.range.select. And the code was in the worksheet private sub under the Activate event. Then I took the code from there removed the select criteria and it almost feels slower. Is there anything I can do to pick up speed? Thank you.
This Example shows how the buttons are positioned up top of each worksheet. There are 10 sheets with these buttons which are shapes.
Example of 1 worksheet with Navigation Buttons on top
Here is the code im using now. This code is in public subs for a general module.
Sub StartPg()
'ChangePagesmacro
With wsStart.Application 'initiate page loading
.Calculation = xlCalculationManual 'turn off calculations
.ScreenUpdating = False 'turn off screen updates
.EnableEvents = False 'disable events
.Goto Reference:=wsStart.Range("A4"), Scroll:=True 'page starting point
With .ActiveWindow
If .FreezePanes Then .FreezePanes = False 'unfreeze panes to remove any jam up`enter code here`
.SplitColumn = 0 'unsplit column to free up screen
.SplitRow = 0 'unsplit row to free up screen
.WindowState = xlMaximized 'maximize window
.DisplayHeadings = False 'turn of page headings
.DisplayFormulas = False ' hide formula bar
.DisplayWorkbookTabs = False 'hide page tabs
.DisplayGridlines = False 'hide gridlines
.DisplayHorizontalScrollBar = True 'show scrollbar
.DisplayVerticalScrollBar = True 'show scrollbar
.Zoom = 81 'zoom and area
.ScrollColumn = 1 'scroll to top
.ScrollRow = 1 'scroll to left
.SplitColumn = 0 'split colum to be frozen
.SplitRow = 3 'split row to be frozen
.FreezePanes = True 'freeze panes
End With
End With
With wsStart
.ScrollArea = "SAStart" 'set user scroll area
With .Application
.Calculation = xlCalculationAutomatic 'turn on calculations
.ScreenUpdating = True ' turn on screen updates
.EnableEvents = True ' turn on events
.DisplayFormulaBar = False 'No formula bar
.DisplayStatusBar = False 'No status bar
.DisplayFullScreen = True ' show full screen
End With
End With
End Sub

How Do I Disable a VBA Sub Using Another Sub

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.

Resources