spot_img

Open And Close Workbook With VBA

In this lesson you can learn how to open and close workbook using VBA code.

Let’s do it in Excel using VBA. You want to have macro which can open and close Excel workbook. Let’s see a VBA code, which does it.

Sub OpenCloseWorkbook()
Dim MonthlyWB As Variant
Dim FileName As String

MonthlyWB = Application.GetOpenFilename( _
FileFilter:="Microsoft Excel Workbooks, *.xls; *.xlsx", 
Title:="Open Workbook")

Workbooks.Open MonthlyWB
FileName = ActiveWorkbook.Name

Workbooks(FileName).Close
End Sub

This macro can open and also close your workbook.

Advantage is that it will also work if a file name changed.

Template

You can download the Template here – Download
spot_img
Previous articleHow To Link Objects In Excel
Next articleGoogle Classroom Tutorial