Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
eliran
Creator III
Creator III

Macro commands to control excel

Hi,

The main reason for this Question is to find out how can I align cells in excel using a macro.

Of course I'm after creating the excel and copying the data to it, I merged couple of cells and want them to be aligned to the center.

I can't seem to find what is the command to do so.

And in a general note, Is there a way to learn / find the commands and properties of the excel?

For example, in Excel, the easiest way to do such things is to record a macro and then view the code generated.

Regards,

Eliran.

1 Solution

Accepted Solutions
amars
Specialist
Specialist

Hi Eliran,

Const xlCenter = -4108

Const xlNone = -4142

Const xlDown = -4121

Const xlRight = -4152

Const xTop = -4160



XLSheet.Range("B1:B2").HorizontalAlignment = xlCenter

XLSheet.Range("B1:B2").VerticalAlignment = xlCenter



Thanks

View solution in original post

5 Replies
amars
Specialist
Specialist

Hi Eliran,

Const xlCenter = -4108

Const xlNone = -4142

Const xlDown = -4121

Const xlRight = -4152

Const xTop = -4160



XLSheet.Range("B1:B2").HorizontalAlignment = xlCenter

XLSheet.Range("B1:B2").VerticalAlignment = xlCenter



Thanks

eliran
Creator III
Creator III
Author

Thanks amars,

Your answer had the missing piece I needed.

i have used:

ExcelDoc.ActiveSheet.Range("B1:D1").HorizontalAlignment = xlCenter

like I'm using in the excel, but it didn't work, I had to declare:

Const xlCenter = -4108

Btw I didn't understand why the extra code you wrote is needed.

Thanks.

amars
Specialist
Specialist

Hi Eliran,

If we don't declare the constant, we never know what the -4108 means thereafter , also the meaning of -4108 . So it is always good to declare the constants & then use it.

Thanks

eliran
Creator III
Creator III
Author

Thanks for replying,

But by extra code I meant, the XlRight/Down/None

I didn't need to use it to get the allignment.

And a follow up question if you may, is there an easy way to get the all the properties that I can use with the Range? for example I also want to play with the boarder colour, In vb it's:

Borders(xlEdgeLeft).TintShade= 0.32131 (some colour I picked up)

How do I know the code that can be used in the qv macro?

Thanks a lot!

Eliran.

Anonymous
Not applicable

I also have a similar problem.

Is there a possibility to open an excel and find any data or record.

I can use loop but i am looking for a simple find syntax.