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 use Macro

Here are the instructions to use above macro procedure in Visual basic editor.

  • Open Visual Basic Editor(VBE) by clicking Alt +F11
  • Go to code window by clicking F7
  • Copy above specified macro or procedure
  • Paste above copied code in code window
  • Run macro by clicking F5 or Run command
  • You can see output on the screen
  • Find above output screenshot of the specified procedure.

Related Workbook Object articles

You may also like the related Workbook Object articles.

VBA Workbook Object

1 thought on “VBA Open Workbook in Excel”

  1. firtukloimutrzas

    I like the helpful info you provide for your articles. I’ll bookmark your weblog and check once more right here regularly. I am rather sure I’ll learn a lot of new stuff right right here! Good luck for the next!

Leave a Comment

Your email address will not be published. Required fields are marked *