VBA disable pop ups - excel

I have a code where I am copying sheets from one excel to another one. There are names that have to be copied over. Whenever that happens, there is a pop up (see below) that I wish to disable. I have tried all of the below, and none seem to work. It seems to work on some computers and not on the others, so there might be something with excel settings.
Application.DisplayAlerts = False
Application.AskToUpdateLinks = False
Application.EnableEvents = False
Application.ScreenUpdating = False
Const ProcName As String = "ListSheets"
Application.AutomationSecurity = msoAutomationSecurityLow
Dim IsSuccess As Boolean
Does anyone know how to fix this?

Maybe try Application.AskToUpdateLinks = False just before opening command lines

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 can I make this code more efficient so that it runs quicker?

I am attempting to hide rows so that only a certain retailers data is shown, the data is not filterable due to the layout of the report. I start by just unhiding all rows as a reset and then manually hide rows that aren't relevant to a retailer until only the clicked retailers info remains.
However this is a slow way of doing this, and I need a quicker way I can understand. There is no criteria to filter the data. Just the retailer name on a click button.
My code shows the manual slow way of doing this.
Sub SummaryRetailer1Only()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
'Resets hidden rows by showing everything.
ActiveSheet.Rows("2:480").EntireRow.Hidden = False
'Hides all rows that don't show data for Retailer1.
ActiveSheet.Rows("18:21").EntireRow.Hidden = True
ActiveSheet.Rows("37:48").EntireRow.Hidden = True
ActiveSheet.Rows("54:57").EntireRow.Hidden = True
ActiveSheet.Rows("73:84").EntireRow.Hidden = True
ActiveSheet.Rows("88:129").EntireRow.Hidden = True
ActiveSheet.Rows("261:376").EntireRow.Hidden = True
ActiveSheet.Rows("390:393").EntireRow.Hidden = True
ActiveSheet.Rows("409:420").EntireRow.Hidden = True
ActiveSheet.Rows("424:427").EntireRow.Hidden = True
ActiveSheet.Rows("443:454").EntireRow.Hidden = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
The code works fine I just want a way that I assume uses some variables so that it runs quicker.
Another way:
Option Explicit
Sub SummaryRetailer1Only()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With ThisWorkbook.Worksheets("Sheet1") '<- It s better to create a with statement with the sheet you want to use insead of activesheet
'Resets hidden rows by showing everything.
.Rows("2:480").EntireRow.Hidden = False
'Hides all rows that don't show data for Retailer1.
Union(.Rows("18:21"), .Rows("37:48"), .Rows("54:57"), .Rows("73:84"), .Rows("88:129"), .Rows("261:376"), _
.Rows("390:393"), .Rows("409:420"), .Rows("424:427"), .Rows("443:454")).EntireRow.Hidden = True
End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

excel vba slowing excel down, causing 10 second egg timer delay when clicking anywhere on sheet

I am using the following vba codes which im using to hide a set of rows and unhide rows depending on if a cell contains text or not, and they are causing my excel spreadsheet to be slow and unresponsive and causing the egg timer to show for about 10 seconds.
If I take the code out It speeds things up so what can I do to my codes to get them to speed up and not take so long? perhaps there is a better way of structuring the code but im really new to vba so am not sure what I would need to do, would appreciate someone's help thanks.
the reason I am using worksheet change and worksheet selection change is so that whether a user clicks on a cell or not the page still updates
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("K22").Value <> "" Then
Application.ScreenUpdating = False
Rows("25:38").EntireRow.Hidden = False
Rows("40:48").EntireRow.Hidden = True
ElseIf Range("K22").Value = "" Then
Rows("25:38").EntireRow.Hidden = True
Rows("40:48").EntireRow.Hidden = False
End If
Application.ScreenUpdating = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("K22").Value <> "" Then
Application.ScreenUpdating = False
Rows("25:38").EntireRow.Hidden = False
Rows("40:48").EntireRow.Hidden = True
ElseIf Range("K22").Value = "" Then
Rows("25:38").EntireRow.Hidden = True
Rows("40:48").EntireRow.Hidden = False
End If
Application.ScreenUpdating = True
End Sub
The main issue is from the Worksheet_Change event, but it could be applied to any event.
The worksheet change is triggering each time you hide a column, so it's trying several times to hide the same columns, before (eventually) failing with an out of memory error:
Hide these columns... Oh, a worksheet change... Hide these columns... Oh, A worksheet change... Hide th...
To avoid this, you need to use
Application.EnableEvents = False
when you decide you are going to make changes, and
Application.EnableEvents = True
when done.
You may also want to put some error handling that turns the events on again, as if something else occurs that stops the code from running, the triggers will be turned off, and the spreadsheet will no longer update as you expect it to.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Application.EnableEvents = False
If Range("K22").Value <> "" Then
Rows("25:38").Hidden = False
Rows("40:48").Hidden = True
Else
Rows("25:38").Hidden = True
Rows("40:48").Hidden = False
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
This works instantly for me:
Application.ScreenUpdating = False
Select Case Range("K22")
Case Is <> ""
Rows("25:38").Hidden = False
Rows("40:48").Hidden = True
Case Else
Rows("25:38").Hidden = True
Rows("40:48").Hidden = False
End Select
Application.ScreenUpdating = True

Screenupdating not flipping

In Excel 2010 the method described below, the ScreenUpdating works correctly. But in 2007, it doesnt flip and the worksheet operations are visually being seen.
VBA Usage:
Dim scrup As Boolean: scrup = DisableScreenUpdating(Application.ScreenUpdating)
Method Declaration:
Function DisableScreenUpdating(val As Boolean) As Boolean
'''''''''''''''''''''''''''''''''''''''''''''''''
' Disable ScreenUpdating, for seemless operation
If val Then
Application.ScreenUpdating = False
End If
'''''''''''''''''''''''''''''''''''''''''''''''''
DisableScreenUpdating = val
End Function
Question:
What am i missing in 2007 that 2010 is either assuming or is working correctly?
Still tracking down the bug cause it is still happening on 1 version of the file but other two versions it will not. The Versions all have the same code-base but based on various settings change representation to the end-user(s).
NOTE:
Please DO NOT focus on the "Why i am doing this", and more of what situations would cause the ScreenUpdating method to NOT be changed from True to False.
You could try eliminating the conditional and see if the problems is still there. That ways you'd know if it has something to do with conditional or not or 'val'.
Function DisableScreenUpdating() As Boolean
Application.ScreenUpdating = False
DisableScreenUpdating = True
End Function
Assuming this makes your bug go away, I'd then focus on the call....
DisableScreenUpdating(Application.ScreenUpdating)
Perhaps the bug something to do with reading the ScreenUpdating property, followed shortly by write. That's just a guess though.
Also, I'd search your project for any other usage of Application.ScreenUpdating. There may be some other code causing the updating to return to True.
For one thing, is there a function to enable ScreenUpdating? Your code only disables it. Here is your code modified with code that I use:
Dim scrup As Boolean: scrup = DisableScreenUpdating(Not Application.ScreenUpdating)
'Disable ScreenUpdating, for seemless operation
Function DisableScreenUpdating(val As Boolean) As Boolean
With Application
If .ScreenUpdating = val Then 'Gets rid of flashes for changing it to the same
.ScreenUpdating = Not val
End If
'Doesn't matter what happens above, this is based on what Excel would send back
DisableScreenUpdating = Not .ScreenUpdating
End With
End Function
I have seen the bug...yet the statement works, only the VBA-editor doesnt see changes.
However you can see the change by assigning a variable and then read it in the VBA-editor.
>Sub testing()
>Dim i As Long
>
>Application.ScreenUpdating = False
>i = Application.ScreenUpdating
>MsgBox "Assigned to i...real value = " & CBool(i)
>
>Application.ScreenUpdating = True
>i = Application.ScreenUpdating
>MsgBox "Value of Application.ScreenUpdating = " & CBool(i)
>End Sub

Resources