Public Sub cmdScan_Click()
'Combinatie van knop 'Scan Picture' en knop 'Kijk of file al bestaat'
On Error GoTo GeenScannerGevonden
Dim FileLocation As String
'Vind de locatie van Mijn Documenten
'Deze functie vind je in Module1
FileLocation = MijnDocumenten & "\Scans Beleggingen\" & Scan
Dim scanDiag As Object
Dim image As Object
Set scanDiag = CreateObject("WIA.CommonDialog")
Set image = CreateObject("WIA.ImageFile")
'Kijken of het bestand bestaat
If Dir(FileLocation) <> "" Then
Dim antwoord As VbMsgBoxResult
antwoord = MsgBox("Het bestand bestaat al. Wil je dit bestand overschrijven?", vbYesNo)
If antwoord = vbYes Then
Kill FileLocation
Else
Exit Sub
End If
End If
Set image = scanDiag.ShowAcquireImage
image.SaveFile FileLocation
MsgBox "Je vindt deze scan in " & FileLocation & "."
Exit Sub
GeenScannerGevonden:
MsgBox "Geen scanner gevonden.", vbCritical
End Sub