明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2629|回复: 5

请教:CAD里的TXET文字如何转到EXCEL里?(下面的代码怎么改)

[复制链接]
发表于 2005-9-22 21:32:00 | 显示全部楼层 |阅读模式

我是初学者,想把CAD的TEXT文字转到EXCEL里,下面是这个想法的代码,但是调试时说是NEXT没有FOR,可能还有其他错误,不知道怎么改,还请高手帮忙指教指教!

Private Sub CommandButton4_Click()
Dim Excel As Excel.Application
    Dim ExcelSheet  As Object
    Dim ExcelWorkbook  As Object
    On Error Resume Next
    Set Excel = GetObject(, "Excel.Application")
    If Err <> 0 Then
        Set Excel = CreateObject("Excel.Application")
    End If
    Set ExcelWorkbook = Excel.Workbooks.Add
    Set ExcelSheet = Excel.ActiveSheet
    ExcelWorkbook.SaveAs "属性表.xls"
Dim ssetobj As AcadSelectionSet
Dim objselected As Object
Dim i As Integer
Dim arry1 As String
Dim rownum As Integer
Dim Count As Integer
Dim arry2 As Variant
Dim cnt As Integer
Dim xcoordinate() As Double
Dim ycoordinate() As Double
Dim temp() As String
Dim x As Integer
Dim y As Integer
On Error GoTo errcontrol
Set ssetobj = ThisDrawing.SelectionSets.Add("mxb")
Dim filtertype(0) As Integer
Dim filterdata(0) As Variant
filtertype(0) = 0
filterdata(0) = "text"
frmain.hide
ssetobj.SelectOnScreen filtertype, filterdata
ReDim xcoordinate(1 To ssetobj.Count), ycoordinate(1 To ssetobj.Count)
ReDim temp(1 To ssetobj.Count)
x = ssetobj.Count
y = ssetobj.Count
i = 0
For Each objselected In ssetobj
If TypeOf objselected Is AcadText Then
arry1 = objselected.textString
arry2 = objselected.InsertionPoint
For cnt = 0 To ssetobj.Count - 1
xcoordinate(cnt) = arry2(0)
ycoordinate(cnt) = arry2(1)
temp(cnt) = arry1
Next cnt
For Count = 1 To y
For rownum = 1 To x
i = i + 1
ExcelSheet.cells(Count, rownum).Value = temp(i)
Next rownum
Next Count
Next objselected
    Excel.Visible = True
    MsgBox "按'确定'键将关闭EXCEL的运行!"
    ExcelWorkbook.Save
    Excel.Application.Quit
    Set Excel = Nothing
errcontrol:
On Error Resume Next
If Not IsNull(ThisDrawing.SelectionSets.Item("mxb")) Then
ThisDrawing.SelectionSets("mxb").Delete
End If
End Sub

发表于 2005-9-22 22:15:00 | 显示全部楼层

VBA 里面的NEXT好像不支持带上变量名称,你把它去掉试试看;

另外建议将objselected 定义为acadentity.

 楼主| 发表于 2005-9-26 17:06:00 | 显示全部楼层
好象还是不能通过
发表于 2005-9-26 17:21:00 | 显示全部楼层

少了一个End if

发表于 2005-9-29 11:53:00 | 显示全部楼层

和我联系,我可以帮你搞定。

我的邮箱:wjingb@gmail.com   QQ:6376627

 

发表于 2005-10-14 10:36:00 | 显示全部楼层
把这句Next objselected中的objselected去掉就可以了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-27 11:41 , Processed in 0.174043 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表