Count Worksheets - Late Binding

M

M

Using the code:

Dim oApp as Object
intCount as Integer

Set oApp = CreateObject("Excel.Application")

oApp.Workbooks.Open("C:\Test.xls")

to open a .xls with late binding, what would I use to
count the worksheets?

And I'm having to use late binding to avoid reference
issues and cannot use early binding. (Thanks to our IT
Dept.)

Thanks

M
 
F

Frank Kabel

Hi
not tested but try
Dim oApp as Object
Dim wbk
intCount as Integer

Set oApp = CreateObject("Excel.Application")

set wbk = oApp.Workbooks.Open("C:\Test.xls")
intcount = wbk.worksheets.count
 
B

Bob Phillips

Dim oApp as Object
Dim oWb as Object
intCount as Integer

Set oApp = CreateObject("Excel.Application")

Set oWb = oApp.Workbooks.Open("C:\Test.xls")

intCount = oWb.Woksheets.Count

--

HTH

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

M

Cookin' with gas! Thanks guys!

M

-----Original Message-----
Dim oApp as Object
Dim oWb as Object
intCount as Integer

Set oApp = CreateObject("Excel.Application")

Set oWb = oApp.Workbooks.Open("C:\Test.xls")

intCount = oWb.Woksheets.Count

--

HTH

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




.
 
T

Tom Ogilvy

Object variables are stored as 32-bit (4-byte) addresses that refer to
objects. Using the Set statement, a variable declared as an Object can have
any object reference assigned to it.


Variant 16 bytes

a few more bytes and a little slower, hardly anything to get emotional
about. Especially for the problem cited.
 

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

Top