VBA 扫描仪扫描图片并插入 Excel
Sub ScanToExcel()
Dim wiaDia As Object Dim wiaImg As Object Dim imgPath As String Dim imgFile As String Dim imgWidth As Integer Dim imgHeight As Integer Dim imgTop As Integer Dim imgLeft As Integer
'Create WIA Dialog Set wiaDia = CreateObject("WIA.CommonDialog")
'Scan Image Set wiaImg = wiaDia.ShowAcquireImage()
'Check if image was scanned If Not wiaImg Is Nothing Then
'Save image to temp folder
imgPath = Environ("temp") & "\scan.jpg"
wiaImg.SaveFile (imgPath)
'Insert image into Excel
With ActiveSheet.Pictures.Insert(imgPath)
'Get image size and position
imgWidth = .Width
imgHeight = .Height
imgTop = .Top
imgLeft = .Left
'Resize and reposition image
.Width = 200
.Height = 200
.Top = 50
.Left = 50
End With
'Delete temp image file
Kill imgPath
End If
End Sub
原文地址: https://www.cveoy.top/t/topic/oeef 著作权归作者所有。请勿转载和采集!