AOB
Well-known Member
- Joined
- Dec 15, 2010
- Messages
- 664
- Office Version
- 365
- 2016
- 2013
- Platform
- Windows
Hi,
Does anybody know if it's possible to do a 'one-off' screen refresh?
I have a macro which takes a bit of time to run so I turn the ScreenUpdating off for the duration, then flick it back on at the end.
However, under certain conditions, it's necessary to prompt a user mid-run to enter some data via a form, and as my macro is passing keys to another application (which may have overlaid the screen and then been minimised) this sometimes means the pop-up form is not immediately obvious to the user (they have to click on the workbook in the taskbar to bring focus back to the workbook, where the form is waiting)
I tried adding a line to re-activate the workbook prior to showing the form but it doesn't seem to have any effect at run-time. Is there a suitable line that I can add to quickly refresh the screen but retain the general mode of no ScreenUpdating?
(I read on MSDN of Application.ScreenRefresh but the compiler doesn't recognise it? Is it only applicable to Word?...)
Or do I just have to switch ScreenUpdating back on, then switch it back off again (seems a bit silly?...)
Shortened version of my code here if it aids understanding...
Does anybody know if it's possible to do a 'one-off' screen refresh?
I have a macro which takes a bit of time to run so I turn the ScreenUpdating off for the duration, then flick it back on at the end.
However, under certain conditions, it's necessary to prompt a user mid-run to enter some data via a form, and as my macro is passing keys to another application (which may have overlaid the screen and then been minimised) this sometimes means the pop-up form is not immediately obvious to the user (they have to click on the workbook in the taskbar to bring focus back to the workbook, where the form is waiting)
I tried adding a line to re-activate the workbook prior to showing the form but it doesn't seem to have any effect at run-time. Is there a suitable line that I can add to quickly refresh the screen but retain the general mode of no ScreenUpdating?
(I read on MSDN of Application.ScreenRefresh but the compiler doesn't recognise it? Is it only applicable to Word?...)
Or do I just have to switch ScreenUpdating back on, then switch it back off again (seems a bit silly?...)
Shortened version of my code here if it aids understanding...
Code:
Function myFunction(Optional myParameter As String) As Boolean[INDENT]
Application.ScreenUpdating = False
' Function code here...
ThisWorkbook.Activate ' This doesn't seem to have the desired effect...
myUserForm.Show ' ...so this form doesn't visibly pop-up
' ...more code...
Application.ScreenUpdating = True
[/INDENT]
End Function