求教根据内容 修改字体的问题
我初学VBA看看书 试着编写了下面这段代码 主要功能就是打开CAD文件后选择所有文字 然后根据文字的内容 修改其属性ThisDrawing.Application.Documents.Open dwgfile
Dim styel1 As AcadTextStyle
Dim fontset As Object
On Error GoTo errcontrol
Dim sname As String
Set fontset = ThisDrawing.SelectionSets.Add("example")
Dim ftype(0) As Integer
Dim fdata(0) As Variant
ftype(0) = 0
fdata(0) = "text"
fontset.Select acSelectionSetAll, , , ftype, fdata
Dim sfont As object
For Each sfont In fontset
‘下面这句如果替换成sfont.height = 10 整个程序就能正常运行
If sfont.TextString = "你好中国" Then
sname = sfont.StyleName
Set style1 = ThisDrawing.TextStyles.Item(sname)
ThisDrawing.ActiveTextStyle = style1
sfont.StyleName = "stardand"
ThisDrawing.ActiveTextStyle.fontFile = "E:\Program Files\AutoCAD Map 3D 2010\Fonts\FZYTK.TTF"
Else
sname = sfont.StyleName
Set style1 = ThisDrawing.TextStyles.Item(sname)
ThisDrawing.ActiveTextStyle = style1
sfont.StyleName = "legend"
ThisDrawing.ActiveTextStyle.fontFile = "E:\Program Files\AutoCAD Map 3D 2010\Fonts\SIMLI.TTF"
End If
sfont.Update
Next sfont
ThisDrawing.SelectionSets("example").Delete
ThisDrawing.Regen acAllViewports
Unload Me
errcontrol:
ThisDrawing.Regen acAllViewports
ThisDrawing.Save
由于初学代码写的肯定存在不少问题 请大侠们不吝赐教 发现问题了就教教我不光关键代码 其他地方也算如果可以写的更精简些那就更好了 呵呵!
非常感谢!
StrComp(string1,string2[,compare]) 返回string1字符串与string2字符串的比较结果,如果两个字符串相同,则返回0,如果小于则返回-1,如果大于则返回1
请问为什么不能用 等于
还有程序别的地方还有什么问题么? 或者哪些代码是多余的
页:
[1]