- Back to Home »
- VBA »
- [VBA] Application_produce
Friday, November 29, 2019
1. ScreenUpdate
Do not update screen display when update content in workbook, worksheet
Application.ScreenUpdating = False
'do something: open/close workbook, edit sheet, ...
Application.ScreenUpdating = True
2. Do not display confirm/waring dialog when save/close/... workbook
3. Display InputTextBox
Option Explicit
Sub DisplayAlerts()
'Do not display warning dialog when save workbook
Application.DisplayAlerts = False
Workbooks("BOOK1.XLS").Close SaveChanges:=True
Application.DisplayAlerts = True
End Sub
Sub InputTextBox_()
Dim Target As String
Target = Application.InputBox("Tu ma ban muon tim kiem:", "Tim kiem", Type:=2)
Debug.Print Target
If Target = "False" Then Exit Sub
'Type
'Value Description
'0 a Formula
'1 a Number
'2 Text (a string)
'4 A logical value (True or False)
'8 A cell reference, as a Range object
'16 An error value, such as #N/A
'64 An array of values
End Sub
4. Wait (sleep)
Sub wait_test()
If Application.Wait(Now + TimeValue("0:00:03")) Then 'wait 3 seconds
Debug.Print "Time expired"
End If
End Sub
5. Status bar
Sub statusbar_test()
Dim oldStatusBar
oldStatusBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
Application.StatusBar = "Please be patient..."
Application.Wait (Now + TimeValue("0:00:03"))
Application.StatusBar = "Time expired"
Application.Wait (Now + TimeValue("0:00:03"))
Application.StatusBar = False
Application.DisplayStatusBar = oldStatusBar
End Sub