EXCEL,将样式表应用于不同的 excel 文件

EXCEL, apply stylesheet to different excel files

目前我有一份工作(其中一项任务)涉及简单地为不同的 excel 文件应用相同的样式、相同的格式。

我想找出简化它的方法。

这种风格 sheet(或某种想法)将需要。

1) Add empty line to very top of the excel file
2) A1-F2 make bold
3) A1-F3 Make full borders
4) A1-F3 Auto Fit Column Width
5) A2-F2 Make colour GREY

我每天都需要对大量文件应用相同的样式。期待简单的解决方案。

您可以使用 MACRO 重新编码器开始。

无论如何,请尝试下面的代码(它将格式化为 "Sheet1"(修改为您请求的 sheet 名称)。

如果要将其应用于所有工作表,则需要循环遍历工作簿中的所有 sheet。

Option Explicit

Sub ApplyExcelShtFormat()

Dim Sht             As Worksheet

' change Sheet name to your needs
Set Sht = ThisWorkbook.Sheets("Sheet1")

With Sht
    ' add 1 Row above the first row
    .Rows("1:1").Insert Shift:=xlDown

    ' modify font to bold
    .Range("A1:F2").Font.Bold = True

    ' add borders all around
    .Range("A1:F3").BorderAround xlContinuous, xlThin

    ' add internal borders
    With .Range("A1:F3").Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    With .Range("A1:F3").Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With

    ' columns auto fit
    .Range("A1:F3").EntireColumn.AutoFit

    ' cell interior color grey (change number according to your kind of gray)
    .Range("A2:F2").Interior.Color = 9868950
End With

End Sub