2016-09-19 48 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 
相關問題