First you need to set a reference (Menu: Tools->References) to the Microsoft Excel Object Library then you can access all Excel Objects. After you added the Reference you have full access to all Excel Objects. You need to add Excel in front of everything for example: Dim xlApp as Excel.Application Let's say you added an Excel Workbook Object in your Form and named it xLObject. Here is how you Access a Sheet of this Object and change a Range Dim sheet As Excel.Worksheet Set sheet = xlObject.Object.Sheets(1) sheet.Range('A1') = 'Hello World' Another way to use Excel in Access is to start Excel through a Access Module (the way shahkalpesh described it in his answer). I dissent from both the answers.
Don't create a reference at all, but use late binding: Dim objExcelApp As Object Dim wb As Object Sub Initialize() Set objExcelApp = CreateObject('Excel.Application') End Sub Sub ProcessDataWorkbook() Set wb = objExcelApp.Workbooks.Open('path to my workbook') Dim ws As Object Set ws = wb.Sheets(1) ws.Cells(1, 1).Value = 'Hello' ws.Cells(1, 2).Value = 'World' 'Close the workbook wb.Close Set wb = Nothing End Sub You will note that the only difference in the code above is that the variables are all declared as objects and you instantiate the Excel instance with CreateObject(). This code will run no matter what version of Excel is installed, while using a reference can easily cause your code to break if there's a different version of Excel installed, or if it's installed in a different location. Also, the error handling could be added to the code above so that if the initial instantiation of the Excel instance fails (say, because Excel is not installed or not properly registered), your code can continue. With a reference set, your whole Access application will fail if Excel is not installed.
Being a disbelieving sod I just tried it, this works in 2002 Sub AtoBtoA() Dim wbA As String ' Set variable to Active workbook name minus the file extension 'wbA = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) wbA = ActiveWorkbook.Name 'go to 'BookB' Windows('BookB.xls').Activate ' return to original workbook ('BookA') THE NEXT LINE IS WHERE IT HANGS UP with a RunTime Error 9 'Subscript out of Range' error message Windows(wbA).Activate ' etc End Sub Actually it hung on the first activate of BookB until I added the xls.
You can use the ‘Activate’ method of Workbook object to activate Workbook using VBA. It is helpful when we have opened multiple workbooks and want to access a.
![Access Vba Activate Excel Workbook Access Vba Activate Excel Workbook](https://i.ytimg.com/vi/oEgp_RjAoAY/hqdefault.jpg)
![Access Vba Activate Excel Workbook Access Vba Activate Excel Workbook](https://www.welkin.com.hk/wp-content/uploads/2016/05/maxresdefault.jpg)
![Activate Excel Workbook From Access Vba Activate Excel Workbook From Access Vba](https://www.excelcampus.com/wp-content/uploads/2015/01/Quickly-Hide-and-Unhide-Multiple-Sheets-with-Tab-Control-Add-in.png)
![Access Vba Activate Excel Workbook Access Vba Activate Excel Workbook](https://msexcel-analysistabs1.netdna-ssl.com/wp/wp-content/uploads/2013/01/VBA-to-hide-unhide-sheets-based-on-conditions.jpg)