VBA Open Workbook

VBA Open Workbook in Excel

VBA Open Workbook is to open an existing workbook. Workbook represents an object. It is part of workbooks collection. Open is method in an Excel VBA. We use this method to open workbook file when it exists in the folder. Once we know the file or workbook path exists in the folder, we open Workbook using open method. It returns the opened workbook.

Syntax for Open Workbook Method

Here is the following syntax to open Workbook.

Workbooks.Open(Filename As Sring, [UpdateLinks], [ReadOnly], [Format], [Password], 
[WriteResPassword], [IgnoreReadOnlyRecommended], [Origin], [Delimiter], [Editable], 
[Notify], [Converter], [AddToMru], [Local], [CorrtptLoad]) As Workbook

Where FileName is a required parameter. It represents the file name of the Workbook. Remaining parameters are optional arguments.

Macro to Open Workbook in Excel VBA

Let us see the following example. It will open Workbook from the specified location.

'VBA Open Workbook in Excel
Sub VBA_Open_Workbook()
    
    'Variable declaration
    Dim sFileName As String
   
    'File Name to Open
    sFileName = "D:\VBAF1\Open_Workbook_File.xlsm"
    
    'Open Workbook
    Workbooks.Open (sFileName)
     
End Sub

If Workbook is not available or doesn’t exists in the specified location, it throws an error. Here is the screen shot of run time error.
RunTime Error

Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays in Excel Blog

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers

Leave a Reply