我有一个运行在macro 2013中的宏,该宏创建的目的是从7500扫描仪上扫描文档,将结果保存为PDF格式,并自动将该文件发送给我们组织中的其他人。
宏本身运行正常,但是与扫描仪附带的HP软件相比,宏的扫描部分花费的时间要长得多。使用惠普软件,扫描23页的时间大约是30秒。在这段时间里,我用宏扫描了大约3-4张。请在下面找到我用来控制扫描仪的代码。有没有人看到任何可以改进或改变以提高执行速度的东西?
Const WIA_FORMAT_JPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
Private Sub cmdOK_Click()
Dim intPages As Integer 'number of pages
Dim img As wia.ImageFile
Dim strPath As String
Dim strPathImg As String
Dim strFileJPG As String
Dim txt_id As String
Dim strRPTScan As String
strPath = "H:\Scan\" 'set path to save files
strPathImg = "H:\Scan\Images\"
intPages = 1
On Error GoTo ErrorHandler
'scan
ScanStart:
Dim DialogScan As New wia.CommonDialog
Dim DPI As Integer
Dim PP As Integer
Dim l As Integer
Dim Scanner As wia.Device
Dim intVerticalExtent As Integer
Dim intOneTwoSided As Integer
Set Scanner = DialogScan.ShowSelectDevice(wia.WiaDeviceType.ScannerDeviceType, False, False)
'Set page length
Select Case fraPaperFormat
Case 1
intVerticalExtent = 1650
strRPTScan = "rptScan11"
Case 2
intVerticalExtent = 2100
strRPTScan = "rptScan14"
End Select
'Set single or two-sided scanning
Select Case fraSingleTwoSided
Case 1
intOneTwoSided = 1
Case 2
intOneTwoSided = 5
End Select
'Set scanner properties depending on userform letter format values
With Scanner
.Properties("3088").Value = intOneTwoSided 'determined above
.Items(1).Properties("Horizontal Resolution").Value = 150
.Items(1).Properties("Vertical Resolution").Value = 150
.Items(1).Properties("6149").Value = 0 'x point to start scan
.Items(1).Properties("6150").Value = 0 'y point to start scan
.Items(1).Properties("Horizontal Extent").Value = 1275
.Items(1).Properties("Vertical Extent").Value = intVerticalExtent 'determined above
End With
'Start Scan if err number -2145320957 Scan document finish
Do While Err.Number <> -2145320957 'error number is ADF status don't feed document
On Error GoTo here
Set img = Scanner.Items(1).Transfer(WIA_FORMAT_JPEG)
strFileJPG = strPathImg & CStr(intPages) & ".jpg"
img.SaveFile (strFileJPG) 'save files .jpg in temp folder
DoCmd.SetWarnings False
DoCmd.RunSQL "insert into scantemp (picture) values ('" & strFileJPG & "')" 'insert picture temp to table scan temp
intPages = intPages + 1 'add number pages
here:
Loop
'after finish scan start convert to pdf任何帮助都将不胜感激。
发布于 2017-05-22 10:41:01
显然,HP应用程序比任何VBA代码都能完成更快的工作,因为HP应用程序可能会命令扫描器扫描ADF中的所有页面,而您只是一个接一个地做。据我所知,使用WIA,你无法解决这个问题。
优化代码的一种方法是首先扫描所有图像并将它们添加到集合中,然后将集合中的所有文件保存到临时文件中,然后在一个查询中将它们添加到数据库中,而不是单独处理每个图像。
一个更优化的扫描解决方案将实现多线程同时扫描和处理扫描。VBA没有多线程的原生实现,但是在web上有几种解决方案,每个解决方案都有各自的局限性。
https://stackoverflow.com/questions/44076555
复制相似问题