您可以使用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
一個Excel文件的工作簿。工作簿可以包含多個工作表。這工作你希望有更新的格式嗎?如果你在上面添加一個空行,第1行是空的。爲什麼你是否將它設置爲粗體?你如何知道每天要更新哪些工作簿?我認爲在你嘗試創建代碼以滿足這個要求之前,你需要考慮穩固的需求。 –
@Bob Moshon嘗試下面的代碼,它將格式化一張表。 –