I have Userform with buttons that are connected to codes. Why buttons keeps being pressed after code has been completed? Is there any way to release them?
Button looks like this after clicking on it:
Button code:
Private Sub ToggleButton2_Click()
ThisWorkbook.Worksheets("Price calculation").Activate
Application.ScreenUpdating = False
ThisWorkbook.Sheets("Price calculation").Unprotect Password:="123"
Range("1867:1979").EntireRow.Hidden = False
ActiveSheet.Shapes("Rectangle: Rounded Corners 76").Visible = False
ActiveSheet.Shapes("Rectangle: Rounded Corners 244").Visible = True
ActiveWindow.ScrollRow = 1867
ThisWorkbook.Sheets("Price calculation").Protect Password:="123"
Application.ScreenUpdating = True
End Sub
You're using a toggle button. These toggle, unsurprisingly. I reckon you are looking to use a CommandButton instead.
In the toolbox browse for the CommandButton control Replace the ToggleButton with the newly added CommandButton. Then, edit the code for your togglebutton and replace it with:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
With ThisWorkbook.Sheets("Price calculation")
.Activate
.Unprotect Password:="123"
.Range("1867:1979").EntireRow.Hidden = False
.Shapes("Rectangle: Rounded Corners 76").Visible = False
.Shapes("Rectangle: Rounded Corners 244").Visible = True
ActiveWindow.ScrollRow = 1867 'Is this necessary? It scrolls to a specific hard-coded row
.Protect Password:="123"
End With
Application.ScreenUpdating = True
End Sub
Related
i have a toggle button that can hide me the chart but i want it to be more designed.
I would like that when the chart is hidden that the button text is 'Show' and backgroundcolor is Red and when he is show, the button is 'Hidden' and background color is Black.
This is my VBA code :
Option Explicit
Sub hidechart()
With ThisWorkbook.Worksheets("CA").Range("45:74,118:147, 192:220, 265:292")
.EntireRow.Hidden = Not .EntireRow.Hidden
End With
End Sub
If ToggleButton1.Value = True Then
Rows(4).EntireRow.Hidden = True
Rows(5).EntireRow.Hidden = True
Rows(6).EntireRow.Hidden = True
Else
Rows(4).EntireRow.Hidden = False
Rows(5).EntireRow.Hidden = False
Rows(6).EntireRow.Hidden = False
End If
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
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.
I'm trying to hide a bunch of images i have placed into a group via a checkbox, I can do this via the same sheet but no on the sheet the textbox is.
Sub hideimages()
If ActiveSheet.CheckBoxes("Check Box 1").Value = 1 Then
ActiveSheet.Shapes("Group 21").Visible = True
Else: ActiveSheet.Shapes("Group 21").Visible = False
End If
End Sub
But i can't seem to figure out the right syntax to get it to affect another sheet for the group I can do it for a singular image:
Sub CheckBox33_Click()
Dim obj As Shape
Set obj = Worksheets("sheet3").Shapes("picture 2")
If obj.Visible Then
obj.Visible = True
Else
obj.Visible = False
End If
How could i merge these? the ways i have tried are not happy!
Sub hidaway()
If Worksheets("sheet1").CheckBoxes("Check Box 34").Value = 1 Then
Worksheets("sheet3").group("Group 21").Visible = True
Else: Worksheets("sheet3").group("Group 21").Visible = False
End If
End Sub
Your checkbox returns True/False so you just need to feed this value to your group visible property:
Private Sub CheckBox1_Click()
ThisWorkbook.Worksheets("Sheet3").Shapes("Group 21").Visible = Me.CheckBox1.Value
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.