Returning an Object with the GetObject Function : GetObject « Application « VBA / Excel / Access / Word






Returning an Object with the GetObject Function

 

 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

 








Related examples in the same category

1.Opening a Database as the Current Database and Closing the Current Database