Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup font and size for entire workbook instead of sheet by sheet?

Tags:

excel

vba

I want my macro to update the entire workbooks font, size and verticalaligment but all I can find are options to do it sheet by sheet. It's not too much hassle, but I was wondering whether you can't set these globally and update the entire workbook with 1 command.

Sub SetFormat()
    With Sheets(1)
        .Cells.Font.Name = "Segoe UI"
        .Cells.Font.Size = 10
        .Cells.VerticalAlignment = xlCenter
    End With
End Sub
like image 948
CustomX Avatar asked Dec 02 '15 09:12

CustomX


2 Answers

If that suits you, you can work on Styles. Changing the default style of the workbook is very quick, but may have side effects. Try it.

With ActiveWorkbook.Styles("Normal").Font
    .Name = "Aharoni"
    .Size = 11
End With
like image 178
iDevlop Avatar answered Oct 17 '22 06:10

iDevlop


This code should loop through every sheet in your workbook and change the properties.

Sub SetFormat()
Dim ws as Worksheet
    For Each ws in Worksheets
         With ws
            .Cells.Font.Name = "Segoe UI"
            .Cells.Font.Size = 10
            .Cells.VerticalAlignment = xlCenter
         End With
    Next ws
End Sub
like image 3
Vulthil Avatar answered Oct 17 '22 05:10

Vulthil