星期三, 九月 20, 2006

Excel Developer Tip: Pausing a Macro to Get a User-Selected Range

目的,停止宏运行,然后让用户选择某个范围的数据range

Sub ProblemCode()
Dim oRangeSelected As Range
On Error Resume Next
Set oRangeSelected = Application.InputBox("Please select a range of cells!", _
"SelectARAnge Demo", Selection.Address, , , , , 8)
If oRangeSelected Is Nothing Then
MsgBox "It appears as if you pressed cancel!"
Else
MsgBox "You selected: " & oRangeSelected.Address(external:=True)
End If
End Sub

这里的inpubox可以改变为一个editor,如果标准Excel显示。