Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Align text in Excel (xlLeft) not working...

Status
Not open for further replies.

PLCBeetle

Programmer
Sep 30, 2008
19
0
0
US
I have an MSAccess 2010 database in which I was using a VBA reference, early binding, and this code to align the text in the cell to the left: newWkSheet.Cells(2, 2).HorizontalAlignment = xlLeft

Due to MSAccess version and reference conflicts I removed the VBA reference and now I am using late binding. Everything is working well now except to align the text in the cell to the left. The following two sample codes below do now not work with late binding:

newWkSheet.Cells(2, 2).HorizontalAlignment = xlLeft
newWkSheet.Range("B1").HorizontalAlignment = xlLeft

Any ideas...? Thanks
 
Here are the declarations:
Dim newExcelApp As Object
Set newExcelApp = CreateObject("Excel.Application")
Dim newWbk As Object
Set newWbk = newExcelApp.Workbooks.Add
Dim newWkSheet As Object
Set newWkSheet = newWbk.Worksheets(1)

Also, these two code samples do not work:
newWkSheet.Range("B1").TextAlign = 1
newWkSheet.Cells(2, 2).TextAlign = 1

I am confused. Thanks
 
for me it works if you use the horizontalalignment property and the literal constant
newWkSheet.Range("B1").horizontalalignment = 1
 
I am with MayP, but I would introduce my own literal constant this way:

Code:
Private Const intMyxlLeft As Integer = 1
...
newWkSheet.Range("B1").horizontalalignment = intMyxlLeft

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
If you do not have a reference to the Excel Object Library, the you cannot use the Excel Constants. As Andy has posted, you must use a descrete value in some way.
 
The OP had cascading mistakes.
First time they used the named constants
newWkSheet.Cells(2, 2).HorizontalAlignment = xlLeft
newWkSheet.Range("B1").HorizontalAlignment = xlLeft

They fixed the named constants but then used the wrong property
newWkSheet.Range("B1").TextAlign = 1
newWkSheet.Cells(2, 2).TextAlign = 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top