We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Auto Format in Excel using VBScript

Medium Priority
Last Modified: 2012-05-06
I'm looking for some code for a VB Script so I can autoformat a worksheet in excel.  I tried using the macro recorder and got the following code but I can't get it to run properly.  
It doesn't have to use the code I have below I am just looking for somethign so I can format my worksheets.  
"ie" is Set ie = CreateObject("excel.Application")

ie.Selection.AutoFormat Format:= xlRangeAutoFormatClassic3, Number:=True, Font:=True, Alignment:=True, Border:=True, Pattern:=True, Width:=True

Open in new window

Watch Question

Top Expert 2010

ie.Selection.AutoFormat Format:=3, Number:=True, Font:=True, Alignment:=True, Border:=True, _
    Pattern:=True, Width:=True

xlRangeAutoFormatClassic3 is equal to 3; in VBScript you cannot use named constants from other libraries.
To get the value for any Excel named constant, just go to Excel's VB Editor, and run something like this in
the Immediate window:



Thanks, I've actually tried that and it gives me an "Expected Statement"  error. What else might I be doing wrong?
Top Expert 2010
Sorry, I forgot that VBScript also does not support passing arguments by name--you can only pass them
by position:

ie.Selection.AutoFormat 3, True, True, True, True, True, True

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.