I've code that takes 30+ mins to run. I have set screen updating to false while most of the code runs but every now and again I turn it to true and straight back to false.
In 2003, 2007 and 2010 this allows the screen to temporarily update. In 2013 it doesn't work.
How can I make Excel 2013 temporarily update the screen mid-macro?
Sub Test()
Application.ScreenUpdating = False
' Do loads of stuff here
Application.ScreenUpdating = True ' Enable to refresh screen
Application.ScreenUpdating = False ' Disable again
' Do more stuff here
Application.ScreenUpdating = True
End Sub
DoEvents worked for me. I don't know what causes this but inserting DoEvents in the Loop Method seems to correct the issue for me when I use it.
Sub LoopMethod
Foreach i in Identity
Call Loopthis
Next For
EndSub
Sub Loopthis
DoEvents
select.Cells(i, 6)
EndSub
I do place this code right before every event/screen I want to update and works fine for me:
Application.ScreenUpdating = True
DoEvents
Sheets("Main").Select 'Screen to update
Also I put the code inside every loop I use to write someting in the Sheet.
Activating another worksheet and then again activating the required worksheet worked for me - I had a code where the screen updating failed, I activated another worksheet and then again the one I was working on, it updated the current screen.
application.ScreenUpdating = False
''''''code'''''''
Thisworkbook.worksheets(any otherworksheet in workbook).activate
Thisworkbook.worksheets(current worksheet).activate
application.ScreenUpdating = True
As far as I have found the issue can be solved by jumping to another cell. You could do something like this:
Dim Ac as object
Set Ac = ActiveCell
Ac.Offset(0,IIf(Ac.Column = Application.Columns.Count, -1, 1)).Activate
Ac.Activate
As to the how or why of this behaviour I don't know (yet). As far as I have found now, it has something to do with the active cell before deactivating screen update, being the same as after reactivating screen update. But I haven
Related
I've got a problem and really need some help from you. I was trying to google the solution, but found nothing useful. My macro runs by clicking on a commandbutton1 which is located on sheet1. Important detail: a chart is also located on sheet1.
The only thing the macro does is switching sheet2 from 'hidden' to 'visible'.
Sub abc()
Sheets(2).Visible = Not Sheets(2).Visible
End Sub
THE PROBLEM: after switching the sheet2 from hidden to visible the screen is flickering.
Notes:
The problem occurs only on the sheets with charts. It seems like excel is doing some chart update.
It occurs only when sheet2 is being switched to "visible".
I've tried:
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationManual
I deleted any other macros and events in the workbook.
I've tried to run a macro directly from VBA editor (not via commandbutton1).
I've tried debugging step by step.
Is there anyone who can help me with this issue?
Through research, it seemed all I needed to do was use this? But my screen still bugs out while refreshing. I am just wanting the screen to not change or do anything at all when running this macro.
Application.ScreenUpdating = False
Here is just a small piece of my code that runs in this macro for reference:
Sub Refresh_Data()
Box.Show
Application.Cursor = xlWait
Application.ScreenUpdating = False
Workbooks("IOM Denial.xlsm").RefreshAll
Workbooks("IOM Denial.xlsm").Worksheets("Home").Activate
Application.Cursor = xlDefault
Application.ScreenUpdating = True
Unload Box
End Sub
You are showing the box in a modal form, Excel is waiting for a response from you before proceeding any further than Box.Show. If you close the Box using the little cross, your code should continue to run.
You can fix this in your code by changing the line to
Box.Show False '<-- runs non-modal
Information from Microsfot here: https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/showmodal-property
I have created a userform to add data in order to generate a report and multiple users will have access to the file containing the userform.However my problem is that everytime i open the ".xlsm" file there are instances where the excel workbook in the background is visible.Also i'm having problems when the userform initiates.I looked for the solution to this on the internet and got a lot many ideas.However,i still did not get what i was looking for and thus am asking the question.
I have tried the following code;
Private Sub Workbook_Open()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.WindowState = xlMinimized
ActiveWindow.WindowState = xlMinimized
'Also tried the following
'1 'Application.Visible = False(Have error running the code if i use this.
It worked fine in excel 2007 but in 2013 and 2016 and higher versions the code won't work properly.No idea why.)
'2 ' With Application (This was basically to hide the visible excel application window behind the userform)`
' .WindowState = xlNormal
' .Height = 500
' .Width = 300
' End With
'do stuff (Cells.ClearContents)
userform1.show
End Sub
I also tried creating and running a ".vbs" file but, it seems to avoid only the excel startup splash screen.
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = false
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\filepath\filename.xlsm")
Following are a few screenshots that might help you understand the problem better.
1: On startup the userform always opens up behind my current window.Is there a way to fix this?
2: Because of the first problem the user usually tends to click on the excel application icon on the task bar.
3: Thus making the workbook/worksheet visible in the background like so.I want to avoid this from happening.No matter what i want the user to see only the userform .Is there something i'm doing wrong?
PS. 1: I also saw that one can put a background image of one's choice to avoid showing the excel worksheet.But since i'm fairly new to vba i really don't know if that would be the best option and haven't tried it yet.I'd prefer tweaking the current code i have (if possible) to get the desired result.
In Excel 2019, the following worked for me:
Attached the following to the Workbook_Open event:
Private Sub Workbook_Open()
Application.Visible = False
UserForm1.Show
End Sub
Created a UserForm with a CommandButton where I did put the following:
Private Sub CommandButton1_Click()
Application.Visible = True
Unload Me
End Sub
Obviously you can use these codes at many more places, but this was just for test purposes:
Edit:
If this does not automatically bring Excel to the forefront, you might want to consider using:
AppActivate Application.Caption
Put that as a first line. Testing this threw an "error 5" to me but looking around the net this is definately not the case to all users. While this is a rare occurence, you can tackle that problem (if you have it) by implementing a waiting time (as that helped me):
Dim HoldOn As Date
HoldOn = DateAdd("s", 10, Now())
Do While Now < HoldOn
Loop
Lower the waiting time if you can as 10 seconds might be a bit much. The whole thing then looks like:
Private Sub Workbook_Open()
Dim HoldOn As Date
HoldOn = DateAdd("s", 10, Now())
Do While Now < HoldOn
Loop
AppActivate Application.Caption
Application.Visible = False
UserForm1.Show
End Sub
I'm facing an odd situation. I have a button on a sheet which runs many functions, being one of those opening another file:
If Not IsItOpen(ENDERECO2) Then
Workbooks.Open Filename:=ENDERECO1
End If
'ENDERECO2 has the file's name
'ENDERECO1 has the full path of the same file
'IsItOpen is a private function as follows:
'Private Function IsItOpen(Name As Variant) As Boolean
' On Error Resume Next
' IsItOpen = Not (Application.Workbooks(Name) Is Nothing)
'End Function
After opening the other workbook, when it isn't already opened, I bring focus to the first sheet, as I want the second one to be opened on the background. To do that, I use:
'At the very beggining of the code
Dim CEL As Range
Set CEL = Selection
'And at the end of it all
CEL.Select
All the described code works perfectly.
The problem I've been having: as this button runs many things at once, I wanted to add an "Application.Screenupdating = False" at the beggining and "... = True" at the end, so it won't flicker too much when calculating. The thing is that when I added the Screenupdating stuff, it will still open the second workbook as desired, but it won't bring the focus back to the main workbook. Instead, it stops at the recently opened workbook and there it stays.
What could be the interference of the Screenupdating on the CEL.Select command?
Any ideas?
Cheers
Thanks Taelsin. Guess when we don't know exactly why, we improvise lol. This worked fine:
If Not IsItOpen(ENDERECO2) Then
Application.ScreenUpdating = True
Workbooks.Open Filename:=ENDERECO1
Application.ScreenUpdating = False
End If
It is good enough. Cheers!
I implemented a google like search box into my spreadsheet, using an activex textbox.. However, in the beginning it worked fine, but now it hides the whole used range and i only see blank cells. This really needs to work 100%, but i can't figure out what's the problem.
The code is as follows:
Sub TextBox1_Change()
Application.ScreenUpdating = False
Range("$O$7").AutoFilter Field:=14, Criteria1:=TextBox1
End Sub
I'd appreciate your help with this issue.
I don't see any statement to clear previous filters, for example:
Worksheets(1).AutoFilterMode = False
Also, there should be Application.ScreenUpdating = True before End Sub to restore screen updating.
If TextBox1.vlaue = "" Then Application.Autofiltermode= False