NickHallick
NickHallick

Reputation: 239

Horizontal align cells in excel from vb6?

I'm working in vb6 and I need to align an excel cell to center. after that(or before whichever works) I need to merge a range of cells including the one that is centered. what I am trying to use right now is this code,

oSheet.range("A1:N1").Merge
oSheet.range("A1").HorizontalAlignment = xlCenter

where oSheet is the excel sheet and xlCenter should be a constant of excel. the problem i am facing is that when i run this code it gives me an error saying that it is unable to set the HorizontalAlignment property of the Range class. this is error 1004. when i go to debug the program and put the mouse over xlCenter it says xlCenter = empty.

Upvotes: 0

Views: 5988

Answers (1)

Tim Williams
Tim Williams

Reputation: 166980

Unless your VB project has a reference to the Excel object library it's not going to know what xlCenter is, so you will need to either:

  • define it as a constant in your VB code

or

  • replace it with the actual value

You can get the value of xlCenter from the object browser in the Excel VB editor.

Upvotes: 1

Related Questions