我用CAD编写一段vba代码,用来统计每张CAD文件中图纸个数并放在excel中,部分代码如下:
-
- Option Explicit
- Type rexcel
- xlapp As Excel.Application
- xlbook As Excel.Workbook
- xlsheet As Excel.Worksheet
- End Type
- Public C As rexcel
- Sub coonExcel(ByVal sp As String)
- Set C.xlapp = CreateObject("excel.application")
- Set C.xlbook = C.xlapp.Workbooks.Open(sp)
- C.xlapp.Visible = True
- Set C.xlsheet = C.xlbook.Worksheets(1)
- C.xlapp.WindowState = xlMinimized
- End Sub
- Sub changeslx(ByVal num As String, ByVal page As String)
- Dim ran As Range
- Dim sh As Excel.Worksheet
- On Error GoTo nex
- For Each sh In C.xlbook.Sheets
- sh.Activate
- sh.Cells.Find(What:=num).Activate
- sh.Cells(ActiveCell.Row, ActiveCell.Column - 1).Activate
- With Selection
- .Value = page
- .Font.color = -16776961
- End With
- Exit Sub
- nex:
- Next sh
- End Sub
可是每当查找到第二张sheet的时候就会报错用On Error也控制不到,求教是什么地方出问题了。
|