Here is my simple code that suits my needs, maybe you'll find it useful:
Code:
Option Compare Database
Option Explicit
'NAPS console usage: https://www.naps2.com/doc-command-line.html
'CHANGE THIS to where ever the naps2 executable is installed on your computer
Const NAPS2Path As String = "C:\Program Files (x86)\NAPS2\NAPS2.Console.exe"
'this sub will execute a shell command and wait for execution to finish
Public Sub RunCmd(cmd As String)
On Error GoTo ErrHandler_RunCmd
'https://stackoverflow.com/questions/15951837/wait-for-shell-command-to-complete
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
'Debug.Print cmd
wsh.Run cmd, windowStyle, waitOnReturn
ExitHandler_RunCmd:
Set wsh = Nothing
Exit Sub
ErrHandler_RunCmd:
Resume ExitHandler_RunCmd
End Sub
Public Sub NAPS2Scan(output As String, Optional profile As String = "Glass", Optional num_of_scans As Byte = 1, Optional delay As Long = 0, Optional wait As Boolean = True)
On Error GoTo ErrHandler_scan
Dim cmd As String
cmd = """" & NAPS2Path & """ -o """ & output & """"
'NAPS console usage: https://www.naps2.com/doc-command-line.html
If profile <> "" Then cmd = cmd & " -p """ & profile & """" 'Specifies the name of the profile to use when scanning. Profiles are defined using the GUI. If this option is not specified, the most-recently-used profile from the GUI is selected.
cmd = cmd & " -n " & num_of_scans 'The number of scans to perform. This may be different from the number of pages scanned (e.g. if you have an automated document feeder).
cmd = cmd & " -d " & delay 'The delay (in milliseconds) between each scan.
If wait Then cmd = cmd & " -w" 'After finishing, wait for user input (enter/return) before exiting
cmd = cmd & " -v" 'Displays progress information.
cmd = cmd & " --progress" 'Displays a graphical window for scanning progress
cmd = cmd & " --disableocr" 'Specifies that OCR should NOT be used when generating PDFs. Overrides --enableocr.
'Debug.Print cmd
RunCmd cmd
ExitHandler_scan:
Exit Sub
ErrHandler_scan:
Resume ExitHandler_scan
End Sub
So let's say you set up a scanning 'profile' in the naps2 gui called 'ADF' to scan from the adf, you would simply run the scanner like this
Code:
NAPS2Scan "D:\Test.pdf", "ADF"