资源描述:
《VBA使用EXCEL读取身份证阅读器获得证件信息.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、VBA使用EXCEL读取身份证阅读器获得证件信息本代码实现了在EXCEL中调用精伦身份证阅读器控件(可在网上百度精伦二次开发包,里面有)读取身份证信息,可根据实际情况修改相关代码,源文件可在EXCELhome网站搜索下载。PrivateDeclareFunctionInitCommLib"Sdtapi.dll"(ByValiPortAsInteger)AsIntegerPrivateDeclareFunctionCloseCommLib"Sdtapi.dll"()AsIntegerPrivateDeclareFun
2、ctionAuthenticateLib"Sdtapi.dll"()AsIntegerPrivateDeclareFunctionReadBaseInfosLib"Sdtapi.dll"(ByValinameAsString,ByValisexAsString,ByValfolkAsString,ByValbirthdayAsString,ByValcodeAsString,ByValaddrAsString,ByValagencyAsString,ByValstartdateAsString,ByValendda
3、teAsString)AsIntegerSub启动_Click()'OnErrorResumeNextDimn,ret,nLenDiminameAsString*31DimisexAsString*3DimfolkAsString*10DimcodeAsString*19DimaddrAsString*71DimbirthdayAsString*9DimstartdateAsString*9DimenddateAsString*9DimagencyAsString*31DimMsgAsString*300DimMs
4、g1AsString*256DimIINSNDNAsString*64DimSAMIDAsString*36DimLenTAsIntegerret=InitComm("1001")IfErrThenErr.ClearMsgBox"端口错误",vbOKOnly,"提示"ExitSubEndIfret=Authenticate()If(ret)Then''MsgBox"找到卡,正在读卡..."'ret=MsgBox("找到卡,正在读卡...",vbOKOnly+vbInformation,"提示")ret=ReadBa
5、seInfos(iname,isex,folk,birthday,code,addr,agency,startdate,enddate)If(ret)Then'MsgBox"读卡成功!"'姓名Range("a1")=Trim(iname)'性别Range("a2")=Trim(isex)'民族Range("a3")=Trim(folk)'出生年Range("a4")=Left(Trim(birthday),4)+"年"+Mid(Trim(birthday),5,2)+"月"+Mid(Trim(birthday),7
6、,2)+"日"Range("b4")=Trim(birthday)'住址Range("a5")=Trim(addr)'公民身份号码Range("a6")=Trim(code)'签发机关Range("a7")=Trim(agency)'有效期限Range("a8")=Trim(enddate)IfTrim(enddate)="长期"ThenRange("b8")=Left(Trim(startdate),4)+"."+Mid(Trim(startdate),5,2)+"."+Mid(Trim(startdate),7
7、,2)+"---长期"ElseRange("b8")=Left(Trim(startdate),4)+"."+Mid(Trim(startdate),5,2)+"."+Mid(Trim(startdate),7,2)+"---"+Left(Trim(enddate),4)+"."+Mid(Trim(enddate),5,2)+"."+Mid(Trim(enddate),7,2)EndIf'显示照片'Pic.Picture=LoadPicture(App.Path+"photo.bmp")ElseMsgBox"读卡
8、不成功!请重新开始读卡。"EndIfElseMsgBox"未找到卡!请将卡远离后再置于机具上。"EndIfret=CloseComm()EndSub