workbook formatting

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

Workbook formatting

resolvedResolved · Low Priority · Version 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:

Move to edge of data block

When data is held in a block, however large, use the Ctrl key with your cursors to move quickly to the far edge of the block. Works with all 4 direction keys.

View all Excel hints and tips


Server loaded in 0.08 secs.