Link to home
Start Free TrialLog in
Avatar of Thanbor
Thanbor

asked on

Excel Formatting from VB

I've got my application to build a spreadsheet, but now I want to make that spreadsheet look good. I need to adjust cell alignments, font face size and weight, row height, column width, set borders, freeze a pane at the top, and protect the whole sheet. How is this done? Where do I find help references for Excel.Application methods and properties?
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

This will do the formatting for the cells in range B6 to I16
(probably cou can also change the rest like this way)

.Range("B6:I16").NumberFormat = "#0.00"
.Range("B6:I16").FontColor = vbRed (can also be color or textcolor)

ASKER CERTIFIED SOLUTION
Avatar of Steiner
Steiner

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MattKilham
MattKilham

For information on Excel.Application, start here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odeopg/html/deovrunderstandingexcelapplicationobject.asp

And for more specific information, search http://msdn.microsoft.com

With regards to formatting your sheet, the easiest way to let Excel do the work for you:

1) Open an Excel sheet
2) Start recording a macro (Tools -> Macros)
3) Perform the formatting you want to know how to do
4) Stop the macro recording

Now, check the source code of the macro in Excel's Visual Basic Editor (Tools -> Macros -> Visual Basic Editor) - most of the code you need will already be in there, you just need to adapt it to work with the Excel.Application object.

Matt
Avatar of Thanbor

ASKER

Thx a lot. Very helpful.