|
请高手帮忙看一下,这个为什么使用VB封装DLL后,运行的时候会报 错误内容:运行时错误:' 424' Object required ,请问是什么原因?本模块中下,感谢帮忙!
Public ACT_cell As Range
Public conn As New ADODB.Connection
Dim rec As New ADODB.Recordset
Public temp_name As String
Public curr_row As Long, curr_clom As Long
Sub MuchSearch()
Dim xlapp As Object
Set xlapp = GetObject(, "Excel.Application")
Dim i As Long, j As Long, sum_row As Long
Dim temp_catlog As String
curr_row = xlapp.ActiveCell.Row
curr_clom = xlapp.ActiveCell.Column
sum_row = Sheet1.Range("d1048576").End(xlUp).Row
conn.CursorLocation = adUseClient
On Error Resume Next
conn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = " & xlapp.ThisWorkbook.Path & "\mydate.accdb;Jet OLEDB:Database Password=yang8848.."
If curr_row <> 1 Then
For j = curr_row To sum_row
If Sheet1.Cells(curr_row, 2).MergeCells = False Then '如果不是标题行就执行查询
temp_catalog = Sheet1.Cells(curr_row, 4).Value
SQL = "select Material,Description,Catalog_name,Brand,Page from [mydate] where Catalog_name Like " & VBA.Chr(34) & temp_catalog & VBA.Chr(34)
On Error Resume Next
rec.Close
rec.Open SQL, conn, adOpenStatic, adLockOptimistic
If rec.RecordCount > 0 Then '如果查询到结果,请添加
Sheet1.Cells(curr_row, 2).Value = rec.Fields(0)
Sheet1.Cells(curr_row, 3).Value = rec.Fields(1)
Sheet1.Cells(curr_row, 4).Value = rec.Fields(2)
Sheet1.Cells(curr_row, 10).Value = rec.Fields(3)
Sheet1.Cells(curr_row, 11).Value = rec.Fields(4)
str1 = "=F" & VBA.CStr(curr_row) & "*(1-G" & VBA.CStr(curr_row) & ")" '写入公式
Sheet1.Cells(curr_row, 8) = str1
str1 = "=E" & VBA.CStr(curr_row) & "*H" & VBA.CStr(curr_row)
Sheet1.Cells(curr_row, 9) = str1
For i = 2 To 9 '标准品或有物料号的取消底色
Sheet1.Cells(curr_row, i).Interior.Color = xlNone
Sheet1.Cells(curr_row, i).Font.Name = "Arial"
Next
Else
Sheet1.Cells(curr_row, 4).Value = VBA.UCase(sheets1.Cells(curr_row, 4))
Sheet1.Cells(curr_row, 2).Value = "Special"
Sheet1.Cells(curr_row, 10).Value = "TOOL"
str1 = "=F" & VBA.CStr(curr_row) & "*(1-G" & VBA.CStr(curr_row) & ")"
Sheet1.Cells(curr_row, 8) = str1
str1 = "=E" & VBA.CStr(curr_row) & "*H" & VBA.CStr(curr_row)
Sheet1.Cells(curr_row, 9) = str1
For i = 2 To 9 '非标品增加黄底色
Sheet1.Cells(curr_row, i).Interior.Color = 65535
Sheet1.Cells(curr_row, i).Font.Name = "Arial"
Next
End If
End If
curr_row = curr_row + 1
Next
End If
conn.Close
End Sub
|
|