MS Excel VBA to assign Font Name and Size

Experts,

I am in the process of setting the workbook Font to Arial and size to 12 and would prefer to print to a single page.

When I call the following code, the cells in the workbook end with Arial and 10.

How can the code be modified or is there another solution?

Sub McrLayout(ws As Worksheet)
' File layout orientation
' Keyboard Shortcut: Ctrl+Shift+L
    Dim i As Long
    Application.PrintCommunication = False
    With ws.PageSetup
        .LeftMargin = Application.InchesToPoints(0.5)
        .RightMargin = Application.InchesToPoints(0.5)
        .TopMargin = Application.InchesToPoints(0.5)
        .BottomMargin = Application.InchesToPoints(0.5)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .Orientation = xlLandscape
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
        .PaperSize = xlPaperLegal
    End With
    With Selection.Font
        .Name = "Arial"
        .FontStyle = "Bold"
        .Size = 12
    End With

    On Error GoTo errhandler
    Application.PrintCommunication = True
    On Error GoTo 0
    Exit Sub
   
errhandler:
    i = i + 1
    If i < 5 Then
        Resume
    Else
        Resume Next
    End If

End Sub
LVL 1
CFMIFinancial Systems AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AccessGuy1763Commented:
CFMI,

I would give "With Sheet.Cells.Font" (in your case "With ws.Cells.Font") a try in place of "With Selection.Font"

Here is my reference:
http://social.msdn.microsoft.com/Forums/office/en-US/fb2e94ed-a2e2-47aa-a3c4-dd795da21899/change-fontname-in-excel-sheet-using-vba?forum=accessdev
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
unknown_routineCommented:
This code:

With Selection.Font
        .Name = "Arial"
        .FontStyle = "Bold"
        .Size = 12
 End With

Should always work (if some cells are selected on worksheet).

The only scenario it may not work is when an error happens and code jump to
errhandler.

put breakpoint on errhandler: and also   .Size = 12 to see if code stops there.
0
CFMIFinancial Systems AnalystAuthor Commented:
Fabulous, the code worked well - Thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.