Microsoft Office Tutorials and References
In Depth Information
Watching the macro recorder
Following is the “cleaned up” FormatChart macro. I changed the code so that
the objects were not selected; I incorporated some simple error-handling; I added
some comments.
Sub FormatChart2()
‘ Exit if a chart is not active
If ActiveChart Is Nothing Then Exit Sub
‘ Make plot area white
With ActiveChart.PlotArea.Interior
.ColorIndex = 2
.Pattern = xlSolid
End With
‘ Make series interior red
With ActiveChart.SeriesCollection(1).Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
‘ Make gridlines dashed, light gray
With ActiveChart.Axes(xlValue).MajorGridlines.Border
.ColorIndex = 15
.Weight = xlHairline
.LineStyle = xlDot
End With
‘ Delete the legend
ActiveChart.HasLegend = False
End Sub
You will, of course, need to understand VBA thoroughly before you start
cleaning up your recorded macros. But for now, just be aware that recorded VBA code
isn’t always the best, most efficient code. But it is an excellent tool to help you
learn about the various object, properties, and methods.
Watching the macro recorder
Excel’s macro recorder translates your mouse and keyboard actions into VBA code.
I could probably write several pages describing how this is done, but the best way
to show you is by example. Follow these steps:
1. Start with a blank workbook.
2. Make sure that Excel’s window is not maximized. You don’t want it to fill
the entire screen.
Search JabSto ::




Custom Search