If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > How to format cells via VBScript code?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-06-04, 13:17
MDesigner MDesigner is offline
Registered User
 
Join Date: Jan 2004
Posts: 65
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!
Reply With Quote
  #2 (permalink)  
Old 02-06-04, 22:18
Smitty Smitty is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 02-06-04, 22:20
Smitty Smitty is offline
Registered User
 
Join Date: Dec 2003
Location: San Diego, CA
Posts: 153
With a bit of editing of course...

Smitty
Reply With Quote
  #4 (permalink)  
Old 02-06-04, 22:25
MDesigner MDesigner is offline
Registered User
 
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"
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On