Click to See Complete Forum and Search --> : How to use Alignment (Center, etc) a cell in an Excell Sheet using VB code?


Raptors Fan
April 9th, 2001, 08:59 PM
Hiya all,

Quick question? How to align a cell in an excell sheet using VB code? Thanx for you help!

GungaDin
April 9th, 2001, 09:37 PM
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