Open Excel file from MS Access using VBA

This is a note for my self when learning the VBA Access. I will show you how to open an Excel file (.xlsx) from Microsof Access Form using VBA. Its not hard to open a Microsoft Excel using VBA from MS Access.

First, we need to add Excel Object library first. To do this, go to Tools | References and look for Microsoft Excel 15.0 ObjectLibrary. Enable it and press OK.

ms excel object library

Now we need to create the following code:

[codesyntax lang=”vbnet”]

Dim AppExcel as Excel.Application
Dim MyWorkbook as Excel.Workbook
Set AppExcel = CreateObject("Excel.Application")
Set MyWorkbook = AppExcel.Workbooks.Open("D:\test.xlsx")
AppExcel.Visible = True
Set AppExcel = Nothing
Set MyWorkbook = Nothing

[/codesyntax]

The code above will open file located in “D:\test.xlsx”

Admin

Leave a Reply

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