Smart questions
Smart answers
Smart people
Join Tek-Tips Forums

Member Login

Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

txmed (Programmer) (OP)
10 Apr 08 16:59
Greetings!  I've created a procedure that dumps data into an excel spreadsheet.  I am using the CreateObject function to create the spreadsheet at run-time.  After I've written all of the data I'm using the EntireColumn.AutoFit() function to autofit all of the columns.

Does anyone know the command for me to adjust all of the columns to left align?  I've searched the web for a while but haven't been able to find here.

Here is some of my code.


Dim xlsApp As Object
Dim xlsBook As Object
Dim xlsSheet As Object

xlsApp = CreateObject("Excel.Application")
xlsBook = xlsApp.Workbooks.Add
xlsSheet = xlsBook.Worksheets(1)

' other code here.


' place code here to set left align.

Thanks in advanced for your help.

Sorwen (TechnicalUser)
10 Apr 08 17:40


xlsSheet.Cells.HorizontalAlignment = xlLeft

-I hate Microsoft!
-Forever and always forward.

Sorwen (TechnicalUser)
10 Apr 08 17:43
Sorry I'm so use to doing that in Excel I forgot it will not know what xlLeft is.


ActiveSheet.Cells.HorizontalAlignment = -4131

-I hate Microsoft!
-Forever and always forward.

bigtimmin (MIS)
11 Apr 08 1:13
You can also try:


xlsSheet.Selection.HorizontalAlignment = xlsApp.Constants.xlGeneral  

txmed (Programmer) (OP)
12 Apr 08 23:35

Thank you for the sample code.  Since I am using late-binding, I'm going to have to use this code:


ActiveSheet.Cells.HorizontalAlignment = -4131

As soon as I get a chance I will try it out.  Thanks for your help!

txmed (Programmer) (OP)
14 Apr 08 22:17
Sorwen, the code you gave me worked.  Thank you so much!

Sorwen (TechnicalUser)
15 Apr 08 10:29
NP.  I'm glad.

-I hate Microsoft!
-Forever and always forward.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close