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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel formatting with vbscript 1

Status
Not open for further replies.

SaMaLaKo

Technical User
Feb 16, 2005
178
BE
Hi all,

I'm searching for the code how to align text in a cell.
anyone an idea?

Thanks

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
KOb3

You might have been better posting this in the VBA forum but here's the code you needed.

Code:
 With Selection
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
 
Thanks dhulbert,

indeed if i was programming in vb this would work,
but apearantly no in vbscript.

Code:
Sub CreateExcelFile (ByVal strExcelPath)
    Dim objXLS, objWorkbks, objWorkbk
    Set objXLS = CreateObject("Excel.Application")
    Set objWorkbks = objXLS.Workbooks	
    Set objWorkbk = objWorkbks.Add
    objXLS.Visible = False
    objXLS.ActiveSheet.Range("A1:E1").Interior.ColorIndex = 17
    objXLS.ActiveSheet.Range("A1:E1").Font.Bold = True
    objXLS.ActiveSheet.Range("A1:E1").Font.Size = 12
    objXLS.ActiveSheet.Range("A1:E1").Font.ColorIndex = 2
    objXLS.ActiveSheet.Range("A1:A500").Interior.ColorIndex = 17
    objXLS.ActiveSheet.Range("A1:A500").Font.Bold = True
    objXLS.ActiveSheet.Range("A1:A500").Font.Size = 12
    objXLS.ActiveSheet.Range("A1:A500").Font.ColorIndex = 2
[COLOR=red]    objXLS.ActiveSheet.Range("A1:A500").HorizontalAlignment = xlLeft
[/color]    objWorkbk.SaveAs (strExcelPath)
    objXLS.Quit
    Set objWorkbk = Nothing
    Set objWorkbks = Nothing
    Set objXLS = Nothing
End Sub

This gives me a 'variable is undefined' error on xlLeft...

I'm looking for the value of the constants like xlLeft...
an idea there?

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
objXLS.ActiveSheet.Range("A1:A500").HorizontalAlignment = &HFFFFEFDD ' xlLeft

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV,
This works...
Can you tell me where i can find these values?
Could come in handy when I need to use the xlCentered or xlRight constant

Greetz...

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
Found them (old ones)



Thanks PHV

--------------------------------------
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
 
Open a blank Excel workbook, go in VBE (Alt+F11), open the immediate (debug) window (Ctrl+G):
? xlLeft
-4131

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top