求举一个例子,CAD里用VBA来替换文字.

例子:把整个图形里的XXXX改为2014.现在正在学习VBA.sub test()✀这里用VBA应该怎么写?end sub万事都只能靠自己....Sub 替换()Dim strDwgName As StringDim strFind As StringDim strReplace As StringDim ent As AcadEntitystrFind = "需要替换的文字"strReplace = "替换后的文字" For Each ent In ThisDrawing.ModelSpace If TypeOf ent Is AcadText Or TypeOf ent Is AcadMText Then With ent If InStr(.textString, strFind) Then .textString = strReplace End With End If Next entEnd Sub
2026年09月27日 14:33
有3个网友回答
网友(1):

替换的我不知道,既然您是学习,我发一段代码给您是修改字体的
Sub ModifyTextFont()
Dim typeFace As String
Dim SavetypeFace As String
Dim Bold As Boolean
Dim Italic As Boolean
Dim charSet As Long
Dim PitchandFamily As Long

ThisDrawing.ActiveTextStyle.GetFont typeFace, Bold, Italic, charSet, PitchandFamily

typeFace = "宋体" '您要设置的字体,这里比如是宋体!!!可自行修改。。。
ThisDrawing.ActiveTextStyle.SetFont typeFace, Bold, Italic, charSet, PitchandFamily
ThisDrawing.Regen acActiveViewport

End Sub

网友(2):

运行后怎么没有反应呢?

网友(3):

为什么要用vba啊,直接用cad命令“find”不成?