Excel VBA to Open Workbook in Background (2 Useful Examples)

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.


Excel VBA to Open Workbook in Background: 2 Practical Examples

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.

Open Secondary Workbook in Background with Excel VBA

  • As a result, the VBA window will pop out.
  • There, double-click ThisWorkbook under the VBAProject (File1.xlsm).

Open Secondary Workbook in Background with Excel VBA

  • 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

code for opening a workbook in background while opening another file

  • 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.

Open Secondary Workbook in Background with Excel VBA

Read More: How to Open Workbook as Read-Only with Excel VBA


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.

VBA Code in Module for Opening Excel Workbook Without Showing

  • 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

code for opening a workbook with macro

  • Save the code by pressing Ctrl and S.
  • Subsequently, close the VBA window.
  • Again, go to the Developer tab.
  • Afterwar, press Macros.

VBA Code in Module for Opening Excel Workbook Without Showing

  • 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


Download Practice Workbook

Download the following workbook to practice by yourself.


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. Don’t forget to drop comments, suggestions, or queries if you have any in the comment section below.


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Aung Shine
Aung Shine

Aung Shine completed his bachelor’s in Electrical and Electronics Engineering from Bangladesh University of Engineering and Technology. It has been almost 2 years since he joined SOFTEKO and actively working on the ExcelDemy project. Currently he works as a Team Leader where he guides his team members to create technical content. He has published 150+ articles and reviewed 50+ articles. He has also solved various user problems before. He has interests in Data Analysis, Power Query, Advanced Excel,... Read Full Bio

2 Comments
  1. The first Application.Screenupdating should be set to False.

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo