Private Sub ExcelExportExample([B][COLOR=red]MySheetPath As String, WorksheetName As String[/COLOR][/B])
'Declare a variable named MySheetPath as String.
Dim MySheetPath As String
[B][COLOR=red]' No need for the three lines below in green[/COLOR][/B]
[B][COLOR=green]'Note: You must change the path and filename below
'to an actual Excel .xlsx file on your own computer.
'MySheetPath = "C:\MySheet.xlsx"
[/COLOR][/B]
'Set up object variables to refer to Excel and objects.
Dim Xl As Excel.Application
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet
'Open an instance of Excel, open the workbook.
Set Xl = CreateObject("Excel.Application")
[B][COLOR=red]Set XlBook = Xl.Workbooks.Open(MySheetPath)[/COLOR][/B]
[B][COLOR=#ff0000][/COLOR][/B]
'Make sure everything is visible on the screen.
Xl.Visible = True
[COLOR=red][B]' This line below, in green, you do not want
[/B][/COLOR][COLOR=green][B]'XlBook.Windows(1).Visible = True
[/B][/COLOR]
[B][COLOR=red]' Change this to select the sheet you wanted by using the variable and [/COLOR][/B]
[B][COLOR=#ff0000]' get rid of the line in green below[/COLOR][/B]
[COLOR=green][B]'Define the topmost sheet in the Workbook as XLSheet.
[/B][/COLOR]Set XlSheet = XlBook.Worksheets([B][COLOR=red]WorksheetName[/COLOR][/B])
'Copy GrandTotal to FromAccess cell in the sheet.
XlSheet.Range("FromAccess").Locked = False
XlSheet.Range("FromAccess") = Me!GrandTotal
'Boldface the new value (optional).
XlSheet.Range("FromAccess").Font.Bold = True
'Save the sheet with the new value (optional).
XlBook.Save
'Close the Access form (optional).
DoCmd.Close acForm, "OrderSummaryForm", acSaveNo
'Clean up and end with worksheet visible on the screen.
Set Xl = Nothing
Set XlBook = Nothing
Set XlSheet = Nothing
End Sub