我是初学者,想把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 |