Using Excel VBA to Open a Workbook in the Background – 2 Examples

This is File1.

This is File2.


Example 1 – Open a Secondary Workbook in the Background with Excel VBA

STEPS:

  • Go to the Developer tab.
  • Select Visual Basic.

Open Secondary Workbook in Background with Excel VBA

  • In the VBA window, double-click ThisWorkbook in VBAProject (File1.xlsm).

Open Secondary Workbook in Background with Excel VBA

  • Enter the following code.
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.
  • Close File1.
  • Open File1 again.
  • File2 will open in the background.

Open Secondary Workbook in Background with Excel VBA

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


Example 2 – Using a VBA Code to Open an Excel Workbook Without Showing it

STEPS:

  • Go to Developer Visual Basic.
  • In the VBA window, click Module.

VBA Code in Module for Opening Excel Workbook Without Showing

 

  • Enter the code below .
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+S.
  • Close the VBA window.
  • Go to the Developer tab.
  • Click Macros.

VBA Code in Module for Opening Excel Workbook Without Showing

  • In the Macro dialog box, choose Open-Workbook in Macro name.
  • Click Run.

It will open File2 in the background.

Read More: How to Open Workbook and Run Macro Using VBA


Download Practice Workbook

Download the following workbook.


 

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