Excel automation problems from VB/VBA

N

numerista

Hi,

I am using Visual Basic 6 to automate Excel.

When the reference to Excel is early bound (bound to Excel at design
time), everything works fine, for example
e.Range(e.Cells(w, x), e.Cells(y,z)).HorizontalAlignment = xlCenter
centers the text in a merged cell.

When changing that to early binding, I get errors telling me that the
HorizontalAlignment is not part of the e.range class, though other
operations work OK.

Anyone have any ideas?

Cheers,
Daniel
 
D

Dave Peterson

When changing to late binding????

Maybe it's not .horizontalalignment that's the problem.

Maybe it's xlcenter.

I'd try
e.Range(e.Cells(w, x), e.Cells(y,z)).HorizontalAlignment = -4108

From Excel's VBE's immediate window:
?xlCenter
-4108
 
N

numerista

Thanks Dave. You've a star!

It seems like when doing early binding, the constants are not set up
in the same way as with late binding...

Ok, so now back to the VBA help for the full codes for the other
constants which also have the same problem (but included in a "on
error goto next" section and so failing silently).

Thanks for the immediate window tip, or I'd be plowing through the VBA
helpfiles!

Cheers,
Daniel
 
D

Dave Peterson

Yep. If you're using a reference, then excel knows what those constants are.

If you don't, then they'll be treated as unitialized. If you add "option
Explicit" to the top of your module, excel won't even let you compile your code
successfully--it won't know what xlCenter is.

You can also search the Object Browser in the VBE (hit F2 to see it) and then
search for your constant.
 

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