Microsoft Excel is a powerful software. We can perform numerous operations on our datasets using Excel tools and features. Another cool feature is the Excel VBA. Those who love coding will find the VBA very useful. We can open workbooks through the VBA method. Sometimes, we have to open some workbooks in the background as a reference to the main workbook we’re working on. In this article, we’ll show you the 2 practical examples of Excel VBA to Open Workbook in Background.
Download Practice Workbook
Download the following workbook to practice by yourself.
2 Practical Examples of Excel VBA to Open Workbook in Background
This article will demonstrate 2 different scenarios of opening an Excel workbook in the background. The first case will be opening a secondary workbook while we open the main one. And the second case is opening a workbook in the background with VBA through the existing workbook. To illustrate, we’ll use 2 Excel files, File1 and File2. File2 is our secondary workbook which we’ll open in the background. Here, File1 is shown in the following picture.
Similarly, the below figure is our File2.
1. Open Secondary Workbook in Background with Excel VBA
In this example, we’ll show you the first scenario. File2 will get opened while we open File1. Therefore, follow the steps below to perform the task.
STEPS:
- First, go to the Developer tab.
- Then, select Visual Basic.
- As a result, the VBA window will pop out.
- There, double-click ThisWorkbook under the VBAProject (File1.xlsm).
- Consequently, a dialog box will appear.
- After that, copy the following code and paste it into the box.
Private Sub Workbook_Open()
 Application.ScreenUpdating = True
 Workbooks.Open Filename:="D:\46\excel vba open workbook in background\File2.xlsx"
 ThisWorkbook.Activate
 Application.ScreenUpdating = False
End Sub
- Save the file.
- Now, close File1.
- Next, open File1 again.
- Immediately, you’ll notice that File2 gets opened in the background.
- See the below picture to understand better.
Read More: How to Remove Background in Excel (2 Practical Cases)
2. VBA Code in Module for Opening Excel Workbook Without Showing
This example will open another workbook through an existing one. So, learn the process below to carry out the operation.
STEPS:
- Firstly, go to Developer ➤ Visual Basic.
- Next, in the VBA window, click Module from the Insert drop-down.
- As a result, the Module window will emerge.
- Then, copy the code below and paste it there.
Sub Open_Workbook()
 Application.ScreenUpdating = True
 Workbooks.Open Filename:="D:\46\excel vba open workbook in background\File2.xlsx"
 ThisWorkbook.Activate
 Application.ScreenUpdating = False
End Sub
- Save the code by pressing Ctrl and S.
- Subsequently, close the VBA window.
- Again, go to the Developer tab.
- Afterwar, press Macros.
- Consequently, the Macro dialog box will pop out.
- Choose Open-Workbook in the Macro name.
- Lastly, press Run.
- Thus, it’ll open File2, but in the background.
- The following image will make it clear for you.
- In this way, you can apply VBA code to open Excel a workbook in the background.
Read More: How to Open Workbook and Run Macro Using VBA (4 Examples)
Conclusion
Henceforth, you will be able to use Excel VBA to Open Workbook in Background following the above-described examples. Keep using them and let us know if you have more ways to do the task. Follow the ExcelDemy website for more articles like this. Don’t forget to drop comments, suggestions, or queries if you have any in the comment section below.
Related Articles
- Make Picture Background Transparent in Excel (2 Methods)
- How to Open Workbook as Read-Only with Excel VBA
- Open Workbook from Path Using Excel VBA (4 Examples)
- How to Open Workbook with Variable Name with Excel VBA
- Make Excel Look Like a Page (with Easy Steps)
- How to Open Folder and Select File Using Excel VBA (4 Examples)
- Make Excel Look Like an Application (with Easy Steps)
The first Application.Screenupdating should be set to False.
Hello Rolan,
Thanks for your suggestion. Article is updated.