[英]formatting and resetting the formatting of excel cells in VBA
在下面的代碼片段中,我在 excel 中使用了兩個 activex label 控件。 拳頭 label(稱為 lblCellAddress) 我根據下面給出的預設值格式化所選單元格。 第二個 label(稱為 lblFormatEraser) 我將單元格的格式設置為默認值,因此它將所選單元格的格式轉換為默認值。
Private Sub lblCellAddress_Click()
'Format the Cells
'--------------------
With Selection
.Font.Size = 12
.Font.Bold = True
.Font.Color = vbBlue
.Font.Name = "Calibri"
.Columns.AutoFit
.Interior.Color = vbGreen
.Borders.Weight = xlThick
'.Borders.Weight = xlThin
.Borders.Color = vbRed
'.BackgroundColor = vbRed
End With
'Format the Label CellFormater
'--------------------
With lblCellAddress
.BackColor = vbRed
.BorderColor = vbGreen
.BorderStyle = fmBorderStyleSingle
.ForeColor = vbBlue
.Font = Calibri
.Shadow = True
.TextAlign = fmTextAlignCenter
End With
' Range("A20").Select
End Sub
'Erase the Cell Formats
'--------------------
Private Sub lblFormatEraser_Click()
With Selection
.Font.Bold = False
.Font.Color = vbBlack
.Interior.Color = xlNone
.Borders.LineStyle = xlNone
End With
'Format the Label CellFormater
'--------------------
With lblFormatEraser
.BackColor = vbGreen
.BorderColor = vbRed
.BorderStyle = fmBorderStyleSingle
.ForeColor = vbBlue
.Font = Calibri
.Shadow = True
.TextAlign = fmTextAlignCenter
End With
End Sub
Private Sub lblCellAddress_Click()
'Format the Cells
'--------------------
With Selection
.Font.Size = 12
.Font.Bold = True
.Font.Color = vbBlue
.Font.Name = "Calibri"
.Columns.AutoFit
.Interior.Color = vbGreen
.Borders.Weight = xlThick
'.Borders.Weight = xlThin
.Borders.Color = vbRed
'.BackgroundColor = vbRed
End With
'Format the Label CellFormater
'--------------------
With lblCellAddress
.BackColor = vbRed
.BorderColor = vbGreen
.BorderStyle = fmBorderStyleSingle
.ForeColor = vbBlue
.Font = Calibri
.Shadow = True
.TextAlign = fmTextAlignCenter
End With
' Range("A20").Select
End Sub
'Erase the Cell Formats
'--------------------
Private Sub lblFormatEraser_Click()
With Selection
.Font.Bold = False
.Font.Color = vbBlack
.Interior.Color = xlNone
.Borders.LineStyle = xlNone
End With
'Format the Label CellFormater
'--------------------
With lblFormatEraser
.BackColor = vbGreen
.BorderColor = vbRed
.BorderStyle = fmBorderStyleSingle
.ForeColor = vbBlue
.Font = Calibri
.Shadow = True
.TextAlign = fmTextAlignCenter
End With
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.