Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    65

    Unanswered: How to format cells via VBScript code?

    I'm trying desperately to find out how to change the formatting of Excel cells via VBScript code... set the alignment, font color, things like that.

    I've spent a good hour on Google and MSDN library, no luck. Help!

  2. #2
    Join Date
    Dec 2003
    Location
    San Diego, CA
    Posts
    153
    Try the Macro Recorder!

    You'll be amazed what that'll produce...

    I.E.
    Code:
    Sub FormatMe()
    
        Cells.Select ' Bad Smitty - Don't Select unless you have to...
    
            With Selection
                .NumberFormat = "$#,##0_);[Red]($#,##0)"
                .HorizontalAlignment = xlRight
                .VerticalAlignment = xlCenter
                .WrapText = False
                .Orientation = 0
                .AddIndent = False
                .ShrinkToFit = False
                .MergeCells = False
                .RowHeight = 17.5
                .ColumnWidth = 12.5
            End With
    
    End Sub
    Hope that helps,

    Smitty

  3. #3
    Join Date
    Dec 2003
    Location
    San Diego, CA
    Posts
    153
    With a bit of editing of course...

    Smitty

  4. #4
    Join Date
    Jan 2004
    Posts
    65
    Thanks!

    I actually found another solution which is easier.. just define styles in the Excel sheet, and then do this to set them:

    Worksheets("blah").Range("A10").Style = "ThisStyle"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •