VBA/Excel/Access/Word/Application/GetObject
Opening a Database as the Current Database and Closing the Current Database
<source lang="vb">
Sub open()
Dim myAccess As Access.Application Dim myDatabase As Object Set myAccess = GetObject(, "Access.Application") myAccess.CloseCurrentDatabase myAccess.OpenCurrentDatabase _ filepath:="C:\mydb.mdb", Exclusive:=True Set myDatabase = myAccess.CurrentDb
End Sub
</source>
Returning an Object with the GetObject Function
<source lang="vb"> Sub Return_a_Value_from_Excel() Dim mySpreadsheet As Excel.Workbook Dim strSalesTotal As String Set mySpreadsheet = GetObject("your.xls") strSalesTotal = mySpreadsheet.Application.Range("SalesTotal").Value Set mySpreadsheet = Nothing Selection.TypeText "Current sales total: $" & strSalesTotal & "." Selection.TypeParagraph End Sub </source>