ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Late Binding (https://www.excelbanter.com/excel-programming/296820-late-binding.html)

Todd Huttenstine[_3_]

Late Binding
 
In the code below, on the 2nd line of code where it says: Set oExcel =
GetObject(, "Excel.Application")
What does the "," in (, "Excel.Application") do? WHy is there a comma
there?

On Error Resume Next
Set oExcel = GetObject(, "Excel.Application")
On Error GoTo 0
If oExcel Is Nothing Then
'Excel wasn't open - open a new one
Set oExcel = GetObject("", "Excel.Application")
End If



Tushar Mehta

Late Binding
 
Check the 'GetObject Function' (w/o the quotes) in XL VBA help.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Business solutions leveraging technology
Microsoft Most Valuable Professional (MVP) 2000-2004

In article ,
says...
In the code below, on the 2nd line of code where it says: Set oExcel =
GetObject(, "Excel.Application")
What does the "," in (, "Excel.Application") do? WHy is there a comma
there?

On Error Resume Next
Set oExcel = GetObject(, "Excel.Application")
On Error GoTo 0
If oExcel Is Nothing Then
'Excel wasn't open - open a new one
Set oExcel = GetObject("", "Excel.Application")
End If




Rob van Gelder[_4_]

Late Binding
 
It looks strange doesn't it.
GetObject has two optional arguments. The comma is just a quick way of
getting to the second argument.
You could just as easily write: Set oExcel =
GetObject(Class:="Excel.Application") but it's longer to type and read.

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Todd Huttenstine" wrote in message
...
In the code below, on the 2nd line of code where it says: Set oExcel =
GetObject(, "Excel.Application")
What does the "," in (, "Excel.Application") do? WHy is there a comma
there?

On Error Resume Next
Set oExcel = GetObject(, "Excel.Application")
On Error GoTo 0
If oExcel Is Nothing Then
'Excel wasn't open - open a new one
Set oExcel = GetObject("", "Excel.Application")
End If





Bob Phillips[_6_]

Late Binding
 
Todd,

This is because GetObject has two parameters, pathname and class. You can
use it by specifying the pathname of a file, or the application class, or
both. If you omit the form er, you must have the latter, a class.

By the way, GetObject is not late binding. You can use GetObject with late
or early binding. What makes it late or early is whether a reference to the
type library is set or not.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Todd Huttenstine" wrote in message
...
In the code below, on the 2nd line of code where it says: Set oExcel =
GetObject(, "Excel.Application")
What does the "," in (, "Excel.Application") do? WHy is there a comma
there?

On Error Resume Next
Set oExcel = GetObject(, "Excel.Application")
On Error GoTo 0
If oExcel Is Nothing Then
'Excel wasn't open - open a new one
Set oExcel = GetObject("", "Excel.Application")
End If






All times are GMT +1. The time now is 09:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com