VBA/Excel/Access/Word/Application/GetObject

Материал из VB Эксперт
Версия от 15:46, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

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>