VBA & Macro Problems

Access VBA: Write to a Specific Open Excel Workbook and Worksheet

Aamir Naveed AkramAamir Naveed Akram Nov 20, 2026 870 views

Question details

Use Access VBA to write data to a named worksheet in an already open Excel workbook.

Write to a Specific Open Excel Workbook and Worksheet with Access VBA
Product
Microsoft Access and Microsoft Excel
Device & OS
not provided
Scenario
An Access VBA procedure needs to use an existing Excel instance and workbook instead of creating a new workbook.
Observed behavior
The procedure should select the specified open workbook and worksheet, then write a value to a cell.
Before you start

Open the target workbook in Excel and check its exact file name, extension, and worksheet tab name. Make sure you can run VBA code in the Access database.

Solution 1Recommended

Connect to the open Excel workbook with GetObject

Use this method when Excel and the target workbook are already open.

GetObject attaches to a running Excel application. The workbook must be open in the Excel instance returned by GetObject; if multiple instances are running, it may not be in the instance you expect.

1
Open the VBA editor

In Access, press Alt+F11 and open an existing module or choose Insert > Module.

2
Add the procedure

Paste this example into the module: Sub WriteToOpenExcelSheet() Dim xlApp As Object Dim xlWbk As Object Dim xlWsh As Object Set xlApp = GetObject(Class:="Excel.Application") Set xlWbk = xlApp.Workbooks("Template.xlsx") Set xlWsh = xlWbk.Worksheets("Data") xlWsh.Range("A1").Value = "Example value" End Sub

3
Match the workbook and sheet

Replace Template.xlsx with the exact name of your open workbook, including its extension, and replace Data with the worksheet tab name. Use .xlsm if that is the workbook's actual extension.

4
Run and check the result

Place the cursor inside the procedure and press F5. In Excel, check cell A1 on the selected worksheet, then save the workbook if you want to keep the change.

Connect to the open Excel workbook with GetObject
If the procedure cannot find Excel or the workbook: Confirm that Excel is running and the workbook is open in the instance returned by GetObject. Check the workbook name, extension, and worksheet name for mistakes.
Free Microsoft Office alternative

Edit Excel Workbooks with WPS Spreadsheet

WPS Office is a free, lightweight alternative with a familiar interface for opening and editing compatible Excel workbooks. It supports migration of common spreadsheet files, but it does not fix or replace Access VBA automation of Microsoft Excel.

Open and edit worksheet cells in WPS Spreadsheet.Work with Microsoft Excel formats such as XLSX and XLSM.Use a familiar spreadsheet interface for an easier transition.Use a free, lightweight office suite.
microsoft office alternative - wps office

Frequently Asked Questions

Does GetObject open the workbook if it is closed?

No. In this example, GetObject connects to a running Excel application, and Workbooks("Template.xlsx") selects a workbook already open in that instance.

Do I need to add an Excel reference in Access?

No. The example declares the Excel objects As Object, so it uses late binding and does not require an Excel object library reference.

Why can't VBA find my open workbook?

Check the exact file name and extension in the Workbooks call. If multiple Excel instances are running, the workbook may be open in a different instance from the one returned by GetObject.

How do I write to a different cell?

Change the address in xlWsh.Range("A1").Value, for example to xlWsh.Range("B2").Value, and assign the value you want.

Does the code save or close the workbook?

No. The example only changes a cell. Use Excel's Save command to keep the change; it leaves the existing workbook and Excel instance open.