kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
I have tried to add some pieces of codes together to produce this piece of algorithm for myself. When I run it and it does not kill nor move any file, then it reports the error message, Run-Time error 5 invalid procedure or argument call then it highlights the line:
The renaming becomes successful. Just that that error prevents the other codes from running. I don’t know if it is best to use the “resume next” statement to force it to run the other codes or not.
I need some deep mind to point out my mistakes for me. Thanks
Note
The variables ImageEnter and ImageChange are global variables that are assigned in a different procedure - in case you wanna know where they are set or defined.
Code:
OriginalFile = Dir
The renaming becomes successful. Just that that error prevents the other codes from running. I don’t know if it is best to use the “resume next” statement to force it to run the other codes or not.
I need some deep mind to point out my mistakes for me. Thanks
Code:
Dim fPath$, oPath$, Ext$, fso As Object
Dim OriginalFile$, FileExists$, OffExists$
Set fso = CreateObject("Scripting.FileSystemObject")
With ThisWorkbook
fPath = .Path & "\PASSPORT PICTURES\"
oPath = .Path & "\PASSPORT OFFLINE\"
End With
OriginalFile = Dir(fPath & ImageEnter & ".*")
FileExists = Dir(fPath & ImageChange & ".*")
OffExists = Dir(oPath & ImageChange & ".*")
If Len(ImageChange) Then
If Len(FileExists) Then
If Len(OffExists) Then Kill oPath & ImageChange & ".*"
fso.movefile Source:=fPath & ImageChange & ".*", Destination:=oPath
End If
While Len(OriginalFile) > 0
Ext = Right(OriginalFile, Len(OriginalFile) + 1 - InStrRev(OriginalFile, "."))
Name fPath & ImageEnter & Ext As fPath & ImageChange & Ext
OriginalFile = Dir
Wend
End If
Note
The variables ImageEnter and ImageChange are global variables that are assigned in a different procedure - in case you wanna know where they are set or defined.