Created
May 27, 2021 09:36
-
-
Save shebpamm/009614455a4370017f136c87283162fa to your computer and use it in GitHub Desktop.
Open scan dialog and save output to desktop with dd/mm/yyyy format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set objFSO = CreateObject("Scripting.FileSystemObject") | |
Function LPad(s, l, c) | |
Dim n : n = 0 | |
If l > Len(s) Then n = l - Len(s) | |
LPad = String(n, c) & s | |
End Function | |
Function FileExists(FilePath) | |
Set fso = CreateObject("Scripting.FileSystemObject") | |
If fso.FileExists(FilePath) Then | |
FileExists=CBool(1) | |
Else | |
FileExists=CBool(0) | |
End If | |
End Function | |
targetTime = Now() | |
'targetTime = CDate("2021-01-01 3:00:00") | |
If Hour(targetTime) <= 5 Then | |
targetTime = DateAdd("d", -1, targetTime) | |
End If | |
set oDlg = CreateObject("WIA.CommonDialog") | |
set image = oDlg.ShowAcquireImage() | |
set WshShell = WScript.CreateObject("WScript.Shell") | |
strDesktop = WshShell.SpecialFolders("Desktop") | |
strFileName = Year(targetTime) & " " & LPad(Month(targetTime), 2, "0") & " " & LPad(Day(targetTime), 2, "0") | |
strCombinedPath = objFSO.BuildPath(strDesktop, strFileName) | |
Dim strFinalFilename : strFinalFilename = strCombinedPath & ".jpg" | |
If FileExists(strCombinedPath & ".jpg") Then | |
Dim i : i = 1 | |
Do While FileExists(strCombinedPath & " (" & i & ").jpg") | |
i=i+1 | |
Loop | |
strFinalFilename = strCombinedPath & " (" & i & ").jpg" | |
End If | |
image.SaveFile(strFinalFilename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment