?
Solved

Excel Formatting from VB

Posted on 2003-03-31
4
Medium Priority
?
176 Views
Last Modified: 2010-05-01
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
Comment
Question by:Thanbor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 8243622
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
 
LVL 11

Accepted Solution

by:
Steiner earned 100 total points
ID: 8243644
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
 

Expert Comment

by:MattKilham
ID: 8243705
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
 

Author Comment

by:Thanbor
ID: 8247814
Thx a lot. Very helpful.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question