简体   繁体   中英

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM