这段程序提示你选择文本,然后指定增量,正的就是加,负的就是减了。如果选中的文本是数字的,那么就对它进行加或减处理。
Sub Test()
Dim SSetObj As AcadSelectionSet
Dim bFound As Boolean
Dim IncreaseValue As Double
Dim i As Integer
On Error GoTo ErrTrap
For Each SSetObj In ThisDrawing.SelectionSets
If SSetObj.Name = "ChangeText" Then
bFound = True
Exit For
End If
Next
If bFound = False Then
Set SSetObj = ThisDrawing.SelectionSets.Add("ChangeText")
Else
Set SSetObj = ThisDrawing.SelectionSets("ChangeText")
SSetObj.Clear
End If
SSetObj.SelectOnScreen
If SSetObj.Count = 0 Then Exit Sub
IncreaseValue = ThisDrawing.Utility.GetReal("指定数值增量: ")
For i = 0 To SSetObj.Count - 1
If TypeOf SSetObj(i) Is AcadText Or TypeOf SSetObj(i) Is AcadMText Then
If IsNumeric(SSetObj(i).TextString) Then
SSetObj(i).TextString = SSetObj(i).TextString + IncreaseValue
End If
End If
Next
SSetObj.Delete
Set SSetObj = Nothing
Exit Sub
ErrTrap:
If Not (SSetObj Is Nothing) Then Set SSetObj = Nothing
On Error GoTo 0
End Sub