When Microsoft talkes about Automation, it is sort of the new word for COM,
but not exactly. It involved manipulating the other application using VBA in
Access. Sometimes, queries and/or tables can be involved.
You use methods like the GetObject and CreateObject to create an instance of
the other application. Once you have established the Application Object, you
use that app's Object Model to control it. For example, with Excel, you
first establish the application object. Then you either create a workbook
object or open an existing .xls file as a workbook object. The you use the
worksheet object to reference and manipulate data, formulas, and formatting
of range objects, cell objects, and other objects and properties of the Excel
Object model.
This includes everything you can do in Excel as if you had it open and were
creating it by hand. You can create charts and graphs, set print areas, set
margins, you name it.
It is a curve getting your head around it, but once you do, it is powerful
stuff. To get started, I picked up a book on Excel VBA, studied the Excel
Object Model using the VBA Object Browser, and by using a trick I read in
this group. That is, if you want to use VBA from Access to do something in
Excel that is new to you, open Excel, start recording a Macro, and when it is
done, open the Macro for editing (now you are in VBA), copy the code, and
paste it into your Access app. There will be some syntactical differences
you will have to adjust, but it is a gread starting point. Just for
starters, here is a sample from one of my apps that establishes the objects.
One word of caution. You have to be very precise in your object referencing
or you can confuse Access and you have to be sure that even if your app
errors out, you destroy the Application object. If you don't, it can leave
an instance of Excel running. You will not see it in Applications tab, but
in the Processes tab. The symptom is that if you try to open Excel and use
it, it will hang up.
Good Luck,
'Open Excel
On Error Resume Next ' Defer error trapping.
Me.txtStatus = "Opening Spreadsheet"
Set xlApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
blnExcelWasNotRunning = True
Set xlApp = CreateObject("excel.application")
Else
DetectExcel
End If
Err.Clear ' Clear Err object in case error occurred.
On Error GoTo LoadAdjustedActuals_Err
DoEvents
xlApp.DisplayAlerts = False
xlApp.Interactive = False
xlApp.ScreenUpdating = False
'Open the Workbook
Set xlBook = xlApp.Workbooks.Open(varGetFileName, 0, True)
Set xlSheet = xlBook.Worksheets("Actuals_res_export")
intLastRow = xlSheet.UsedRange.Rows.Count
If intLastRow = 0 Then
MsgBox "No Data to Import" & vbNewLine & "Spreadsheet may be open by
another user", _
vbExclamation + vbOKOnly, "Import Adjusted Actuals"
GoTo LoadAdjustedActuals_Exit
End If