Excel VBA Open Macro - excel

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!

Related

Excel 2019 still displays save prompt even when the Application.EnableEvents = False

I tried all the different blocks of codes below but when I close the Excel, it still prompts whether to save or not.
I have the code in the Workbook BeforeClose event.
I am using excel 2019 and Windows 11
I tried this,
Application.EnableEvents = False
Application.DisplayAlerts = False
ThisWorkbook.Saved = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
this,
Application.DisplayAlerts = False
ThisWorkbook.Saved = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
and this,
Application.EnableEvents = False
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
Am I missing something?
Application.Calculation = xlCalculationAutomatic is a workbook change. Hence the previous saved state is no longer valid. You can confirm this easily enough my doing the same thing manually. i.e. toggle calculation state after a save and attempt to close the book.
Interestingly enough, it you save one book with Auto calc on and close it. Then save another with Auto calc off and close it. The calc state will be reflected by whichever you next open. That is to say, it's saved in the workbook (not the application). Excel resolves conflicts by adopting the current state to any subsequent books opened.
This isn't new by the way. Been like that as long as I can remember. Which, unfortunately, is too long :)

Is possible extract or delete worksheet from one closed workbook without open it?

I have two workbooks, one is for work (A) and the other only has usage data (B). File B has more than 25000 records and when I open it using VBA there is a long delay in loading.
One option I thought of was to delete the sheets with the data that I don't need but should delete them without opening the B file.
The second option would be to copy the data from the sheet without opening file B.
Currently, I am using Set wbOrigen = Workbooks.Open (FileName: = xxxxxx) but I need to speed up the load.
Is it possible to do any of this?
As far as I know it is not possible to access a Workbook's data without opening it. But from my experience this is not a problem (as this is very fast) as long as you remember to close it in the end.
The "standard" trick to improve performance is to disable ScreenUpdating and Events like such:
Application.ScreenUpdating = False
Application.EnableEvents = False
' Open Workbook, Load data, do some operations, close Workbook
Application.ScreenUpdating = True
Application.EnableEvents = True
Thanks but I already using those declarations, that is not the problem.
Public Sub TLD_StartMacro()
With Application
.ScreenUpdating = False
.Calculation = Excel.xlCalculationManual
.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
.CutCopyMode = False
.DisplayAlerts = False
End With
End Sub
Public Sub TLD_EndMacro()
With Application
.DisplayAlerts = True
.ScreenUpdating = True
.Calculation = Excel.xlAutomatic
.EnableEvents = True
.CutCopyMode = False ' Esta sentencia vacĂ­a el portapapeles
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.

how to disable zoom slider through excel vba?

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.

Make window open in background

I have 3 input boxes that when a document is selected it opens the document and fills in a select box. With Excel 2013 these windows are opened in front of the document and have to be minimized in order to select the next one. Is there a way to have it automatically open documents in the background?
Workbooks.Open (file_path)
If Application.Version >= 15# Then
ActiveWindow.WindowState = xlMinimized
End If
This what I currently have, however I would rather it open in the background in the first place over having to minimize it. I have tried to turn off screen updating for the part, however that did not work.
Application.ScreenUpdating = False
Workbooks.Open (file_path)
Application.ScreenUpdating = True
Does Application.ScreenUpdating affect WorkBooks.open in Excel 2013?
Application.ScreenUpdating will not work with excel 2013.
You may try creating function:
Sub myScreenUpdate(screenUpdateRequest As Boolean, previousScreenUpdate As Boolean)
If screenUpdateRequest Then
Application.ScreenUpdating = previousScreenUpdate
Else
previousScreenUpdate = Application.ScreenUpdating
Application.ScreenUpdating = False
End If
End Sub
call req:
Call myScreenUpdate(False, previousScreenUpdate)
Call myScreenUpdate(True, previousScreenUpdate)
Dim previousScreenUpdate as boolean
Call myScreenUpdate(False, previousScreenUpdate) 'to get the current setting into previousScreenUpdate
Call myScreenUpdate(True, false) 'to set updating to false
'do your heavy code here and when finished:
Call myScreenUpdate(True, previousScreenUpdate)

Resources