我如何清理和删除logging的macros中不必要的步骤?

我是VBA的新手,我正在整理下面logging的macros,并删除任何默认情况下的细节,并不需要在那里或删除任何不必要的细节,只是杂乱无章代码。 任何人都可以给一些build议?

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("Heading 1")相关的所有行都可以分组,并将整个代码包含在With..End With结构中。 同样正常的样式:

 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 

一般来说,你也将要删除所有的Activate 。 Intead的

 Range("g2").Activate ActiveCell.Value = 6 

你会写: Range("g2").Value = 6