自定义一个函数,将其中的uid登陆用户,pwd密码,tns数据库以及sql中的表名等替换,然后将代码写到excel的vba中,在excel中使用自定义函数即可
Function get_box(barcode)
uid = "****"
pwd = "****"
tns = "****"
Set conn = CreateObject("ADODB.Connection")
dsntemp = "Provider=MSDAORA.1;Data Source= " & tns & "; User ID=" & uid & ";password=" & pwd
conn.Open dsntemp
Sql = "SELECT box_no from table where barcode='" & barcode & "'"
Set rs = conn.Execute(Sql)
If Not rs.EOF Then
get_box = rs(0)
Else
get_box = "未查询到数据!"
End If
Set rs = Nothing
conn.Close
Set conn = Nothing
End Function
我之前做过类似的事,条码是用扫描枪输入的吧?
如果你的数据量不是特别大的话,建议导出数据到excel,然后用vlookup来做