2016-09-19 84 views
0

目前我有一份工作(哪一项任务)只涉及简单地为不同的excel文件应用相同的样式,相同的格式。EXCEL,将样式表应用于不同的excel文件

我想找出简化它的方法。

此样式表(或某种想法)将需要。

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 

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

+0

一个Excel文件的工作簿。工作簿可以包含多个工作表。这工作你希望有更新的格式吗?如果你在上面添加一个空行,第1行是空的。为什么你是否将它设置为粗体?你如何知道每天要更新哪些工作簿?我认为在你尝试创建代码以满足这个要求之前,你需要考虑稳固的需求。 –

+0

@Bob Moshon尝试下面的代码,它将格式化一张表。 –

回答

1

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

无论如何,尝试下面的代码,如果你想将它应用到所有表(将其格式化为“工作表Sheet1”(修改您请求的工作表的名称)。

,那么你就需要通过所有表圈在工作簿中。

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