Microsoft Office Tutorials and References
In Depth Information
ActiveSheet.Name = szSheetName
The DisplayAlerts property determines if Microsoft Excel will display alerts while a macro is
running. By changing the value to False , Excel will choose the default response for all alerts
that would have been displayed; the one exception is when using the SaveAs method for
workbooks. When DisplayAlerts is Tr ue , the OverWrite alert has a default response of Yes, but
Excel will use No as a response when DisplayAlerts is False .
Excel will reset the DisplayAlerts property to the default value of Tr ue when the macro completes.
The following macro, which removes all unused worksheets from a workbook, sets the
DisplayAlerts property to False so that the user isn’t prompted every time the macro attempts
to delete a worksheet:
Warning You must run this workbook on a workbook that contains some data. If you run
this on a new workbook with nothing but empty sheets, you get VB runtime error 1004:
"A workbook must contain at least one visible sheet."
Dim intCount As Integer
Application.DisplayAlerts = False
For intCount = Sheets.Count To 1 Step -1
If Selection.Address() = "$A$1" And ActiveCell = "" Then
intCount = Sheets.Count + 1
The RangeSelection property returns a Range object that represents the selected cells on the
selected workbook. Even when a graphic object is selected, the RangeSelection property will
return a range of cells, returning the last cells that were selected.
When cells are selected, the RangeSelection property and the Selection object both represent
the same cells. When a graphic object is selected, the RangeSelection property will still return
the last cells that were selected.