Link to home
Start Free TrialLog in
Avatar of jforbes
jforbes

asked on

Formatting Excel via VB

I am currently working on an app in Access that uses Excel as the Report Generator, this way my client can edit the report with ease.  My question is how can I programmatically format the columns to fit the longest Item, and how can I format a cell with a custom format such as currency/Percentage, an how can I center text in a cell?

Thanks in advance.

-John
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Use this:

mobjXL.Columns("A:Z").EntireColumn.AutoFit
mobjXL.Range("A1").Select
Avatar of jforbes
jforbes

ASKER

Sorry I guess I wasn't clear on the last part.  I know how to select a range, what method do I call or use once the range is selected to center columns and add custom formats.

Thanks so far the autofit works.

-John
ASKER CERTIFIED SOLUTION
Avatar of Chrynoble
Chrynoble

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
The easiest way to find out what methods to use in Excel is to record a macro and perform the change. Looking at the automatically generated code will give you a guide to use.
Avatar of jforbes

ASKER

Thanks a million, I never would have thought about using a macro, works like a charm.  Makes it nice when you are able to cheat honestly for code.

Thanks again.

-John