xkaeli 发表于 2012-4-28 09:57:21

求助EXCEL查找问题

我用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也控制不到,求教是什么地方出问题了。

linlq986 发表于 2012-10-29 20:09:29

本帖最后由 linlq986 于 2012-10-29 20:19 编辑

刚才看错了
页: [1]
查看完整版本: 求助EXCEL查找问题