Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

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?
0
Thanbor
Asked:
Thanbor
1 Solution
 
DhaestCommented:
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)

0
 
SteinerCommented:
Personally I found the built-in help for ExcelVBA quite helpful.

Since your application already builds the spreadsheet, I assume that you have a reference to the Excel Object Library in your project.
Just press F2 to show the object catalogue, select the Excel Library and look for a class called "Range". That shows you all properties, methods and events the range-object has. By pressing F1 VB should show you help to the command you've selected.
You can find help on the application, workbook and worksheet object just the same way.

Another way of finding the right properties would be to use Excel and record a macro while you do the changes manually. The you can enter the VBA-Editor (F11) and have a look at the generated code and pick the lines you want.
0
 
MattKilhamCommented:
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
0
 
ThanborAuthor Commented:
Thx a lot. Very helpful.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now