How to use Alignment (Center, etc) a cell in an Excell Sheet using VB code?
Hiya all,
Quick question? How to align a cell in an excell sheet using VB code? Thanx for you help!
Re: How to use Alignment (Center, etc) a cell in an Excell Sheet using VB code?
The following example shows how to set Horizontal and vertical alignment
Dim xlApp as new Excel.Application
Dim xlWorkbook as Excel.Workbook
Dim xlSheet as Excel.Worksheet
xlApp.Visible = true
set xlWorkbook = xlApp.Workbooks.Add
set xlSheet = xlWorkbook.Sheets(1)
With xlSheet.Cells(1, 1)
.Value = "Hello"
.HorizontalAlignment = xlCenter ' Center
.HorizontalAlignment = xlRight ' Right Align
.HorizontalAlignment = xlLeft ' Left Align
.VerticalAlignment = xlBottom ' Bottom
.VerticalAlignment = xlCenter ' Center
.VerticalAlignment = xlTop ' Top
End With
xlWorkbook.Close false
xlApp.Quit
Hope this helps,
Nathan Liebke