Mackeral
Board Regular
- Joined
- Mar 7, 2015
- Messages
- 249
- Office Version
- 365
- Platform
- Windows
Looking in Google to find out about aligining, you find references to xlVAlign and xlHAlign which define code to do this aligning. So you would think you could write a subroutine to do this. But you can't.
The basic problem is that both sets of code (both horizontal and vertical alignments) reference the constant "xlCenter", and VBA doesn't allow you to access a constant more that one time. It will also not allow you to redefine it with another line in an Enum like "YlCenter = xlCenter". There are also some other variables that are shown in the Google documentation that I found just don't work in Alignments as they work in VBA now: xlJustivied, xlDistributed.
To get around this problem, you will need to execute the following code to make these alignment changes:
Mac Lingo
The basic problem is that both sets of code (both horizontal and vertical alignments) reference the constant "xlCenter", and VBA doesn't allow you to access a constant more that one time. It will also not allow you to redefine it with another line in an Enum like "YlCenter = xlCenter". There are also some other variables that are shown in the Google documentation that I found just don't work in Alignments as they work in VBA now: xlJustivied, xlDistributed.
To get around this problem, you will need to execute the following code to make these alignment changes:
Code:
Enum Horizontal_Aligns
hrz_left = xlLeft
hrz_right = xlRight
hrz_center = xlCenter
End Enum
Enum Vertical_Aligns
vrt_Top = xlTop
vrt_Middle = xlCenter
vrt_Bottom = xlBottom
End Enum
Sub Cells_Align_Horizontal(SHEET as Worksheet, Rng, _
Optional What_to_Do As Horizontal_Aligns = hrz_left)
' Do Horizontile Alignment of cells.
SHEET.Range(Rng).HorizontalAlignment = What_to_Do
End Sub ' Cells_Align_Horizontal
Sub Cells_Align_Vertical(SHEET as Worksheet, Rng, _
Optional What_to_Do As Vertical_Aligns = vrt_Center)
' Do Vertical Alignment of cells.
SHEET.Range(Rng).VerticalAlignment = What_to_Do
End Sub ' Cells_Align_Vertical
Mac Lingo