Excel 如何从录制的宏中清除和删除不必要的步骤?

Excel 如何从录制的宏中清除和删除不必要的步骤?,excel,vba,formatting,Excel,Vba,Formatting,我是VBA新手,我希望整理一下下面记录的宏,删除默认情况下插入的任何细节,不需要在那里,或者删除任何不必要的细节,只是把代码弄得乱七八糟。有人能给点建议吗 With ActiveWorkbook.Styles("Normal") .IncludeNumber = True .IncludeFont = True .IncludeAlignment = True .IncludeBorder = True .IncludePatterns = Tr

我是VBA新手,我希望整理一下下面记录的宏,删除默认情况下插入的任何细节,不需要在那里,或者删除任何不必要的细节,只是把代码弄得乱七八糟。有人能给点建议吗

     With ActiveWorkbook.Styles("Normal")
    .IncludeNumber = True
    .IncludeFont = True
    .IncludeAlignment = True
    .IncludeBorder = True
    .IncludePatterns = True
    .IncludeProtection = True
End With
ActiveWorkbook.Styles("Normal").NumberFormat = "#,##0.0;[Red](#,##0.0);-"
With ActiveWorkbook.Styles("Heading 1")
    .IncludeNumber = False
    .IncludeFont = True
    .IncludeAlignment = False
    .IncludeBorder = True
    .IncludePatterns = True
    .IncludeProtection = False
End With
ActiveWorkbook.Styles("Heading 1").Borders(xlLeft).LineStyle = xlNone
ActiveWorkbook.Styles("Heading 1").Borders(xlRight).LineStyle = xlNone
ActiveWorkbook.Styles("Heading 1").Borders(xlTop).LineStyle = xlNone
With ActiveWorkbook.Styles("Heading 1").Borders(xlBottom)
    .LineStyle = xlContinuous
    .ThemeColor = 4
    .TintAndShade = 0
    .Weight = xlThick
End With
ActiveWorkbook.Styles("Heading 1").Borders(xlDiagonalDown).LineStyle = xlNone
ActiveWorkbook.Styles("Heading 1").Borders(xlDiagonalUp).LineStyle = xlNone
With ActiveWorkbook.Styles("Heading 1").Interior
    .Pattern = xlSolid
    .PatternColorIndex = 0
    .ThemeColor = xlThemeColorLight2
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With
With ActiveWorkbook.Styles("Heading 1")
    .IncludeNumber = False
    .IncludeFont = True
    .IncludeAlignment = False
    .IncludeBorder = True
    .IncludePatterns = False
    .IncludeProtection = False
End With
With ActiveWorkbook.Styles("Heading 2")
    .IncludeNumber = False
    .IncludeFont = True
    .IncludeAlignment = False
    .IncludeBorder = True
    .IncludePatterns = False
    .IncludeProtection = False
End With
ActiveWorkbook.Styles("Heading 2").Borders(xlLeft).LineStyle = xlNone
ActiveWorkbook.Styles("Heading 2").Borders(xlRight).LineStyle = xlNone
ActiveWorkbook.Styles("Heading 2").Borders(xlTop).LineStyle = xlNone
With ActiveWorkbook.Styles("Heading 2").Borders(xlBottom)
    .LineStyle = xlContinuous
    .ThemeColor = 4
    .TintAndShade = 0
    .Weight = xlThick
End With
ActiveWorkbook.Styles("Heading 2").Borders(xlDiagonalDown).LineStyle = xlNone
ActiveWorkbook.Styles("Heading 2").Borders(xlDiagonalUp).LineStyle = xlNone
With ActiveWorkbook.Styles("Heading 4")
    .IncludeNumber = False
    .IncludeFont = True
    .IncludeAlignment = False
    .IncludeBorder = False
    .IncludePatterns = False
    .IncludeProtection = False
End With
With ActiveWorkbook.Styles("Heading 4").Font
    .Name = "Calibri"
    .Size = 11
    .Bold = True
    .Italic = False
    .Underline = xlUnderlineStyleNone
    .Strikethrough = False
    .ThemeColor = 2
    .TintAndShade = 0
    .ThemeFont = xlThemeFontMinor
End With
  With ActiveWorkbook.Styles("Total")
    .IncludeNumber = False
    .IncludeFont = True
    .IncludeAlignment = False
    .IncludeBorder = True
    .IncludePatterns = False
    .IncludeProtection = False
End With
ActiveWorkbook.Styles("Total").Borders(xlLeft).LineStyle = xlNone
ActiveWorkbook.Styles("Total").Borders(xlRight).LineStyle = xlNone
With ActiveWorkbook.Styles("Total").Borders(xlTop)
    .LineStyle = xlContinuous
    .ThemeColor = 2
    .TintAndShade = 0
    .Weight = xlThin
End With
With ActiveWorkbook.Styles("Total").Borders(xlBottom)
    .LineStyle = xlContinuous
    .ThemeColor = 2
    .TintAndShade = 0
    .Weight = xlThin
End With
ActiveWorkbook.Styles("Total").Borders(xlDiagonalDown).LineStyle = xlNone
ActiveWorkbook.Styles("Total").Borders(xlDiagonalUp).LineStyle = xlNone
ActiveWindow.SmallScroll Down:=21
ActiveWorkbook.Styles("Percent").NumberFormat = "0.00%;[Red](0.00%);-"
End Sub

在这个特定的示例中,与
ActiveWorkbook.Styles(“标题1”)
相关的所有行都可以分组,并将整个代码封装在
结构中,以..结尾。标准样式的Idem:

With ActiveWorkbook.Styles("Normal")
    .IncludeNumber = True
    .IncludeFont = True
    .IncludeAlignment = True
    .IncludeBorder = True
    .IncludePatterns = True
    .IncludeProtection = True
    .NumberFormat = "#,##0.0;[Red](#,##0.0);-"
End With   
With ActiveWorkbook.Styles("Heading 1")
    .IncludeNumber = False
    .IncludeFont = True
    .IncludeAlignment = False
    .IncludeBorder = True
    .IncludePatterns = True
    .IncludeProtection = False
    .Borders(xlLeft).LineStyle = xlNone
    .Borders(xlRight).LineStyle = xlNone
    .Borders(xlTop).LineStyle = xlNone
    .Borders(xlBottom)
    .LineStyle = xlContinuous
    .ThemeColor = 4
    .TintAndShade = 0
    .Weight = xlThick
End With
通常,您还需要删除所有
激活
。Intead of

Range("g2").Activate
ActiveCell.Value = 6
您可以这样写:
Range(“g2”)。Value=6