- 积分
- 34652
- 明经币
- 个
- 注册时间
- 2003-11-28
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2015-12-21 15:43:37
|
显示全部楼层
以下是我的一段文字替代的程序,供参考。找到关键字后搜索。
Sub replacetext2()
Dim Excelapp As Application
Dim currentrow As Integer
Call LinkExcel(Excelapp) '连接excel
Dim I As Integer, J As Integer
Dim Oldtext As String, Newtext As String, replaced As Boolean
replaced = False
Dim ssetObj As AcadSelectionSet
Set ssetObj = CreateSelectionSet("textobj")
currentrow = Excelapp.ActiveCell.Row
Dim FType, FData
BuildFilter FType, FData, -4, "<or", 0, "text", 0, "mtext", -4, "or>"
ssetObj.SelectOnScreen FType, FData
For J = Excelapp.Selection.Row To Excelapp.Selection.Row + UBound(Excelapp.Selection.Formula) - 1
replaced = False
For I = 0 To ssetObj.Count - 1
If ssetObj.Item(I).textString = Excelapp.Cells(J, 1).Value Then
ssetObj.Item(I).textString = Excelapp.Cells(J, 20).Value
ssetObj.Item(I).Update
ssetObj.Item(I).Color = acBlue
replaced = True
End If
Next I
If replaced = False Then
ActiveDocument.Utility.Prompt vbLf & Excelapp.Cells(J, 1).Value & "未替换,请检查!" & vbCr
Else
Excelapp.Cells(J, 1).Value = Excelapp.Cells(J, 20).Value
End If
Next J
ssetObj.Clear
MsgBox "管道编号替换完毕!"
'excelapp.Visible = True
End Sub |
|