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.


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.

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 = True
End Sub

Open Secondary Workbook in Background with Excel VBA

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

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 = True
End Sub

VBA Code in Module for Opening Excel Workbook Without Showing

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

Aung

Aung

I'm Aung. Recently I earned my B.Sc. Degree in Electrical and Electronic Engineering. From now on, I will be working in Microsoft Excel and other useful software, and I’ll upload articles related to them. My current goal is to write technical contents for anybody and everybody that will make the learning process of new software and features a happy journey.

We will be happy to hear your thoughts

Leave a reply

ExcelDemy
Logo