When you implement a process to open an external Excel file using Excel VBA, the target file often fills the screen and gets in the way. In this article, I learned how to open files in the background and suppress screen updates, so I will introduce the steps and code.
What I Want to Achieve
- I want to open external Excel files without showing them to the user.
- I want to quietly process files opened temporarily for automation in the background.
Method: Suppress Screen Rendering with ScreenUpdating Property
VBA has a property called Application.ScreenUpdating. By setting this to False, you can suppress screen flickering and display updates during processing. By using this feature, it becomes possible to open external files without displaying them to the user.
VBA Code Used
Below is the basic code to open an external Excel file in the background.
Sub OpenWorkbookSilently()
Dim ExternalWorkbook As Workbook
' Turn off screen updating
Application.ScreenUpdating = False
' Open the external Excel file
Set ExternalWorkbook = Workbooks.Open("C:\Users\s_mori\OneDrive - MACCS.cloud\デスクトップ\ショートカット\01_SKY関係\SKY_ED.xlsx")
' Perform necessary processing (reading, copying, etc.) here
' Turn screen updating back on
Application.ScreenUpdating = True
End Sub
Key Points of the Code
- Application.ScreenUpdating = False Stops screen updates before opening the file. This ensures the file is not displayed on the Excel screen.
- Workbooks.Open(…) Opens the external Excel file as usual. It becomes accessible from the VBA side.
- Application.ScreenUpdating = True Restores the original state by resuming screen updates after the process is finished.
Notes
ScreenUpdatingcontrols the display; it does not open the file in a strictly “invisible” mode. In some environments, you might briefly see window switching.- If an error occurs during processing,
ScreenUpdating = Truemight not be called, leaving the screen frozen. In such cases, it is safer to addOn Errorhandling.
Summary
Using Application.ScreenUpdating is effective for opening external Excel files in the background.
- Stop screen updating, then open the file.
- Resume screen updating after processing.
- Execute VBA processes without the user noticing.
This is a very useful technique for automation purposes such as routine tasks and batch processing. I hope this article helps you.
