我正试图找出一个问题,因为这个想法是为了缩短"使用With命令的代码。下面是我到目前为止的代码。我很好奇为什么你不能在with命令下使用shtThisSheet变量时直接有一个括号。
全部谢谢!
Option Explicit
Sub Formatting()
Dim shtThisSheet As Worksheet
Set shtThisSheet = ActiveWorkbook.Worksheets("Sheet1").Range
With shtThisSheet
.Font.Bold = True
.Font.Size = 14
.HorizontalAlignment = xlLeft
. ("A3:A6").Font.Bold = True
.("A3:A6").Font.Italic = True
.("A3:A6").Font.ColorIndex = 5
.Range("A3:A6").InsertIndent 1
.Range("B2:D2").Font.Bold = True
.Range("B2:D2").Font.Italic = True
.Range("B2:D2").Font.ColorIndex = 5
.Range("B2:D2").HorizontalAlignment = xlRight
.Range("B3:D6").Font.ColorIndex = 3
.Range("B3:D6").NumberFormat = "$#,##0"
End With
End Sub
答案 0 :(得分:0)
Option Explicit
Sub Formatting()
Dim shtThisSheet As Worksheet
Set shtThisSheet = ActiveWorkbook.Worksheets("Sheet1")
With shtThisSheet
With .Range("A3:A6")
.Font.Bold = True
.Font.Size = 14
.HorizontalAlignment = xlLeft
.Font.Bold = True
.Font.Italic = True
.Font.ColorIndex = 5
.Range("A3:A6").InsertIndent 1
End With
With .Range("B2:D2")
.Font.Bold = True
.Font.Italic = True
.Font.ColorIndex = 5
.HorizontalAlignment = xlRight
End With
With .Range("B3:D6")
.Font.ColorIndex = 3
.NumberFormat = "$#,##0"
End With
End With
End Sub