K
K
KTG2016-11-02 03:07:19
Automation
KTG, 2016-11-02 03:07:19

WIA error setting PAGES (VBA) option. Why?

Sub scan()
    Dim objDM As WIA.DeviceManager
    
        Dim objDev As WIA.Device
        
            Dim objItem As WIA.Item
            Dim objImage As WIA.ImageFile
        
        Dim s As String
        Dim i As Integer
        
        Dim p As Property
       
     Set objDM = New WIA.DeviceManager
     For i = 1 To objDM.DeviceInfos.Count
        If objDM.DeviceInfos(i).Type = 1 Then
          s = objDM.DeviceInfos(i).DeviceID
        End If
     Next
     
     Set objDev = objDM.DeviceInfos(s).Connect
     If objDev Is Nothing Then
        MsgBox ("Error: Not device found")
     Else
        objDev.Properties("Document Handling Select").Value = 1
        objDev.Properties("Pages").Value = 1
        
            Set objItem = objDev.Items(1)
            Set objImage = objItem.Transfer(WIA.FormatID.wiaFormatTIFF)
'            objImage.SaveFile "c:\test\" & ActiveCell.Value & ".TIFF"
            
        Set objItem = Nothing
        Set objImage = Nothing
        Set objDev = Nothing
     End If
     
     Set objDev = Nothing
     Set objDM = Nothing
    
End Sub

As far as I understood, the line
objDev.Properties("Document Handling Select").Value = 1

responsible for where the paper comes from and what type of scan. , In this case, the paper is missing from the auto feed tray.
The same line is responsible for the number of scanned pages from the tray.
objDev.Properties("Pages").Value = 1
If set to 0, then it should automatically scan all that are in the tray.
If 1 - then only 1 sheet.
So. For some reason, when changing the number of pages,
for example: objDev.Properties("Pages").Value = 0
It gives an error about an incorrectly specified parameter and highlights the following line in Debug:
Set objImage = objItem.Transfer(WIA.FormatID.wiaFormatTIFF)

How to be?
I can't detect if there is paper in the ADF.
Although, in theory, the MFP provides for this, at least when trying to scan and not laying paper, it reports this.
As an extreme option, I left the solution in the loop until the OnError error was issued.
But it seems to me that this is not entirely correct.
And yes. For some reason, constants don't work in VBA, WIA_DPS_PAGES for example.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question