Late Binding

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

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
 
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
 
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.
 
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top