kingbo.camera
Thành viên mới

- Tham gia
- 7/6/21
- Bài viết
- 3
- Được thích
- 0
Mình muốn dùng code vba chọn file ảnh CCCD cho ra thông tin, code không đọc được nhờ các cao nhân xem giúp:
Function ReadQRCode(ImagePath As String) As String
Dim objShell As Object
Dim objExec As Object
Dim strCommand As String
Dim strOutput As String
' Ðu?ng d?n d?n file ?nh QR
'Dim imagePath As String
'imagePath = "C:\path\to\qrcode.png"
' T?o d?i tu?ng Shell
Set objShell = CreateObject("WScript.Shell")
' L?nh g?i ZBar d? d?c QR code
strCommand = "cmd /c zbarimg.exe" & ImagePath
' Th?c thi l?nh
Set objExec = objShell.Exec(strCommand)
' Ð?c d? li?u t? QR code
Do While Not objExec.StdOut.AtEndOfStream
strOutput = objExec.StdOut.ReadLine()
Debug.Print strOutput ' In k?t qu? vào Immediate Window (Ctrl + G d? m?)
Loop
' Hi?n th? k?t qu? trong Excel
Range("A1").Value = strOutput
' D?n d?p b? nh?
Set objExec = Nothing
Set objShell = Nothing
End Function
Sub SelectAndReadQRCode()
Dim fd As FileDialog
Dim filePath As String
Dim result As String
' M? h?p tho?i ch?n file
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Title = "Ch?n ?nh CCCD"
fd.Filters.Add "Hình ?nh", "*.jpg; *.png; *.bmp", 1
fd.AllowMultiSelect = False
If fd.Show = -1 Then
filePath = fd.SelectedItems(1)
result = ReadQRCode(filePath)
MsgBox "N?i dung mã QR: " & result, vbInformation, "K?t Qu?"
End If
End Sub
Function ReadQRCode(ImagePath As String) As String
Dim objShell As Object
Dim objExec As Object
Dim strCommand As String
Dim strOutput As String
' Ðu?ng d?n d?n file ?nh QR
'Dim imagePath As String
'imagePath = "C:\path\to\qrcode.png"
' T?o d?i tu?ng Shell
Set objShell = CreateObject("WScript.Shell")
' L?nh g?i ZBar d? d?c QR code
strCommand = "cmd /c zbarimg.exe" & ImagePath
' Th?c thi l?nh
Set objExec = objShell.Exec(strCommand)
' Ð?c d? li?u t? QR code
Do While Not objExec.StdOut.AtEndOfStream
strOutput = objExec.StdOut.ReadLine()
Debug.Print strOutput ' In k?t qu? vào Immediate Window (Ctrl + G d? m?)
Loop
' Hi?n th? k?t qu? trong Excel
Range("A1").Value = strOutput
' D?n d?p b? nh?
Set objExec = Nothing
Set objShell = Nothing
End Function
Sub SelectAndReadQRCode()
Dim fd As FileDialog
Dim filePath As String
Dim result As String
' M? h?p tho?i ch?n file
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Title = "Ch?n ?nh CCCD"
fd.Filters.Add "Hình ?nh", "*.jpg; *.png; *.bmp", 1
fd.AllowMultiSelect = False
If fd.Show = -1 Then
filePath = fd.SelectedItems(1)
result = ReadQRCode(filePath)
MsgBox "N?i dung mã QR: " & result, vbInformation, "K?t Qu?"
End If
End Sub