- 积分
- 10513
- 明经币
- 个
- 注册时间
- 2002-6-3
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2002-10-26 14:23:00
|
显示全部楼层
Re:如何用VBA编写查找替换
函数如下:
OldText-要查找的文字
NewText-替换文字
Sub ReplaceText(ByVal OldText As String, ByVal NewText As String)
Dim EntObj As AcadEntity
On Error GoTo ErrTrap
For Each EntObj In ThisDrawing.ModelSpace
If StrComp(EntObj.ObjectName, "AcDbText", vbTextCompare) = 0 _
Or StrComp(EntObj.ObjectName, "AcDbMText", vbTextCompare) = 0 Then
If StrComp(EntObj.TextString, OldText, vbTextCompare) = 0 Then
EntObj.TextString = NewText
End If
End If
Next
Set EntObj = Nothing
Exit Sub
ErrTrap:
If Not (EntObj Is Nothing) Then Set EntObj = Nothing
On Error GoTo 0
End Sub
调用方法如下:
Sub Main()
ReplaceText "2", "12"
End Sub |
|