ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 895|回复: 1

哪位高手能用Excel读取身份证

[复制链接]

TA的精华主题

TA的得分主题

发表于 2019-11-6 15:45 | 显示全部楼层 |阅读模式
哪位高手能用Excel读取身份证?

TA的精华主题

TA的得分主题

 楼主| 发表于 2019-11-6 15:59 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
本帖最后由 HHP628 于 2019-11-6 16:02 编辑

Private Declare Function InitComm Lib "Sdtapi.dll" (ByVal iPort As Integer) As Integer
Private Declare Function CloseComm Lib "Sdtapi.dll" () As Integer
Private Declare Function Authenticate Lib "Sdtapi.dll" () As Integer
Private Declare Function ReadBaseInfos Lib "Sdtapi.dll" (ByVal iname As String, ByVal isex As String, ByVal folk As String, ByVal birthday As String, ByVal code As String, ByVal addr As String, ByVal agency As String, ByVal startdate As String, ByVal enddate As String) As Integer

Sub 启动_Click()

    'On Error Resume Next
    Dim n, ret, nLen
    Dim iname As String * 30
    Dim isex  As String * 3
    Dim folk As String * 10
    Dim code As String * 19
    Dim addr As String * 71
    Dim birthday As String * 9
    Dim startdate As String * 9
    Dim enddate As String * 9
    Dim agency As String * 31
    Dim Msg As String * 300
    Dim Msg1 As String * 256
    Dim IINSNDN As String * 64
    Dim SAMID As String * 36
    Dim LenT As Integer
   
    ret = InitComm("1001")

    If Err Then
        Err.Clear
        MsgBox "端口错误", vbOKOnly, "提示"
        Exit Sub
    End If
    ret = Authenticate()
    If (ret) Then '
       'MsgBox "找到卡,正在读卡..."
       'ret = MsgBox("找到卡,正在读卡...", vbOKOnly + vbInformation, "提示")
         ret = ReadBaseInfos(iname, isex, folk, birthday, code, addr, agency, startdate, enddate)
         If (ret) Then
          ' MsgBox "读卡成功!"
            
           '姓名
            Range("B5") = Trim(iname)
            
            '性别
            Range("G5") = Trim(isex)
            
            '民族
            Range("aa5") = Trim(folk)
            
            '出生年
            Range("aa6") = Left(Trim(birthday), 4) + "年" + Mid(Trim(birthday), 5, 2) + "月" + Mid(Trim(birthday), 7, 2) + "日"
            Range("aa7") = Trim(birthday)
            '住址
             Range("B10") = Trim(addr)
            
            '公民身份号码
            Range("B6") = Trim(code)
            
            '签发机关
            Range("aa10") = Trim(agency)
            
            '有效期限
            Range("aa11") = Trim(enddate)
            If Trim(enddate) = "长期" Then
                Range("aa12") = Left(Trim(startdate), 4) + "." + Mid(Trim(startdate), 5, 2) + "." + Mid(Trim(startdate), 7, 2) + "---长期"
            Else
                Range("aa12") = 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)
                Range("aa13") = Left(Trim(startdate), 4) + "." + Mid(Trim(startdate), 5, 2) + "." + Mid(Trim(startdate), 7, 2)
            End If
            '显示照片
            'Pic.Picture = LoadPicture(App.Path + "\photo.bmp")
            
        Else
        
            MsgBox "读卡不成功!请重新开始读卡。"
        
        End If

        
    Else
        MsgBox "未找到卡!请将卡远离后再置于机具上。"
    End If
     ret = CloseComm()
End Sub



目前这段代码运行时在红色的地方报错,求帮助解决!
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-3-28 17:14 , Processed in 0.043042 second(s), 10 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表