Does macro change font automatically when clsoing workbook and how do I get to do on mutiple sheets

ghrek

Active Member
Joined
Jul 29, 2005
Messages
427
Hi

I have the following macro and trying to find out if it will automatically change the font and save it when the workbook closes and how do I do it for mutiple sheets in same workbook.


Private Sub Workbook_Close()
Cells.Select
With Selection.Font
.Name = "Daytona Condensed"
.FontStyle = "Regular"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Range("A5308").Select
Selection.End(xlUp).Select
ActiveWindow.SmallScroll Down:=-6
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi @ghrek , thanks for posting on the forum.

You didn't mention if it's all the sheets of the book or just some.
for mutiple sheets in same workbook.

I present to you the 2 alternatives.

For all sheets:
VBA Code:
Private Sub Workbook_Close()
  Dim sh As Worksheet
  Application.ScreenUpdating = False
  For Each sh In Sheets
        sh.Select
        With sh.Cells.Font
          .Name = "Daytona Condensed"
          .FontStyle = "Regular"
          .Size = 11
          .Strikethrough = False
          .Superscript = False
          .Subscript = False
          .OutlineFont = False
          .Shadow = False
          .Underline = xlUnderlineStyleNone
          .TintAndShade = 0
          .ThemeFont = xlThemeFontNone
        End With
        sh.Range("A5308").End(xlUp).Select
  Next
  Application.ScreenUpdating = True
End Sub

For some sheets, but you must indicate the name in this line of the macro:
VBA Code:
Case "Sheet1", "Sheet2", "report", "etc"

Then:
VBA Code:
Private Sub Workbook_Close()
  Dim sh As Worksheet
  Application.ScreenUpdating = False
  For Each sh In Sheets
    Select Case sh.Name
      Case "Sheet1", "Sheet2", "report", "etc"
        sh.Select
        With sh.Cells.Font
          .Name = "Daytona Condensed"
          .FontStyle = "Regular"
          .Size = 11
          .Strikethrough = False
          .Superscript = False
          .Subscript = False
          .OutlineFont = False
          .Shadow = False
          .Underline = xlUnderlineStyleNone
          .TintAndShade = 0
          .ThemeFont = xlThemeFontNone
        End With
        sh.Range("A5308").End(xlUp).Select
    End Select
  Next
  Application.ScreenUpdating = True
End Sub

--------------
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
--------------
 
Upvote 0
Many thanks

Its the all sheets one that im going to use. One thing I just noticed and didnt think about was if the workbook is "read only" dont run the macro when closing. Can that be added to it?
 
Upvote 0
is "read only" dont run the macro
Try this:

VBA Code:
Private Sub Workbook_Close()
  Dim sh As Worksheet
  
  If ThisWorkbook.ReadOnly = True Then Exit Sub
  
  Application.ScreenUpdating = False
  For Each sh In Sheets
        sh.Select
        With sh.Cells.Font
          .Name = "Daytona Condensed"
          .FontStyle = "Regular"
          .Size = 11
          .Strikethrough = False
          .Superscript = False
          .Subscript = False
          .OutlineFont = False
          .Shadow = False
          .Underline = xlUnderlineStyleNone
          .TintAndShade = 0
          .ThemeFont = xlThemeFontNone
        End With
        sh.Range("A5308").End(xlUp).Select
  Next
  ThisWorkbook.Save
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top