Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

workbook formatting

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Workbook formatting

Workbook formatting

ResolvedVersion 2010

Thea has attended:
Excel VBA Intro Intermediate course

Workbook formatting

Please can you advise how I can format the font, font size and alignment of an entire workbook containing approx 20 worksheets using VBA?

Thanks

Edited on Tue 15 Apr 2014, 16:33

RE: Workbook formatting

Hi Thea

Thanks for getting in touch. There are probably a couple of ways but you probably want a FOR EACH structure like the following:

Dim ws As Worksheet

For Each ws in ActiveWorkbook.Worksheets

<formatting code>

Next ws

This will loop through every sheet in the workbook and perform the actions you specify. You should prefix all the pieces with ws to make sure the code targets them correctly. For example, the following code will loop through every sheet in the book, horizontally aligning all the cells centrally, bolding the first row, make all cells size 18, and making the first column red (try this on a test workbook, not your existing data!):

Sub FormatMyWorkbook()

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets

ws.Cells.HorizontalAlignment = xlCenter

ws.Rows(1).Font.Bold = True
ws.Cells.Font.Size = 18
ws.Columns(1).Interior.Color = vbRed

Next ws

End Sub

I hope this gives you enough pointers to modify yourself. You can probably record the formatting components you need and adapt accordingly. Let me know if you have any specific formatting you can't figure out.

Kind regards

Gary Fenn
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Workbook formatting

This is very helpful, thank you Gary

Tue 22 Apr 2014: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

New Normal Worksheet

Do you want all your worksheets to confirm to a certain look? Then change the Defaults!!!
1. Press Shift+F11 to create a new worksheet
2. Press Ctrl+A to select (higlight) all cells, Press Ctrl+1, make any formatting changes then click OK.
3. Press F12 (Function 12 key) click in the Save As Type, drop down, then select Template (*.xlt)
4. Click in the Save in drop-down, then find the folder; c:_program files_microsoft office_office_start. (For the underscores shown use backslash)
Name your templete sheet.xlt, then press Enter.
Sheet.xlt is used when you insert a new worksheet (Shift+F11)

Note: These changes are permanent changes on your PC.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.