Excel VBA, Open a Closed Workbook

I recommend readers to read the article below to further familiarize themselves with the process of automation:


The code below will open the workbook located in the path D:StuffBusinessTempTempFile.xlsx”:

Sub Example1()
Dim objWorkbook As Workbook
Set objWorkbook = Workbooks.Open("D:StuffBusinessTempTempFile.xlsx")
End Sub

Open File Dialog:

The code below will display an open file dialog and ask the user to select the location of the file to open:

Sub Example2()
Dim intChoice As Integer
Dim strPath As String
Dim objWorkbook As Workbook
'only allow the user to select one file
Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
'make the file dialog visible to the user
intChoice = Application.FileDialog(msoFileDialogOpen).Show
'determine what choice the user made
If intChoice <> 0 Then
    'get the file path selected by the user
    strPath = Application.FileDialog( _
    Set objWorkbook = _
End If
End Sub


Open File Dialog
You can download the file and code related to this article from the link below:

See also:

If you need assistance with your code, or you are looking for a VBA programmer to hire feel free to contact me. Also please visit my website  www.software-solutions-online.com

2 thoughts on “Excel VBA, Open a Closed Workbook”

Leave a Reply

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