Simeon
New Member
Hi all,
i work on a project with a file Upload to an external Network. I posted my code here in the past and now it works well with my Upload:
For reference: https://chandoo.org/forum/threads/concatenate-in-vba-can-somebody-help-please.45034/
Only one thing is missing and i'm stuck:
Every to upload file has his own folder on the network.
Now i need a way to check if a file already exisits in the folder before the Upload begins. If yes, the Macro should move this file into a sub-folder called "Archive".
If there is no subfolder called "Archive" the macro has to create a folder. Every folder has his own Archiv.
E. g. C:/Targetfolder/LEG001/Archive
I posted my Code in the past here on the forum but here is it one more time:
Has somebody an idea how i can implement the needed checking before Upload?
Thanks for your help in advance
Simeon
i work on a project with a file Upload to an external Network. I posted my code here in the past and now it works well with my Upload:
For reference: https://chandoo.org/forum/threads/concatenate-in-vba-can-somebody-help-please.45034/
Only one thing is missing and i'm stuck:
Every to upload file has his own folder on the network.
Now i need a way to check if a file already exisits in the folder before the Upload begins. If yes, the Macro should move this file into a sub-folder called "Archive".
If there is no subfolder called "Archive" the macro has to create a folder. Every folder has his own Archiv.
E. g. C:/Targetfolder/LEG001/Archive
I posted my Code in the past here on the forum but here is it one more time:
Code:
Option Explicit
Sub File_Upload()
'Activate Microsoft Scripting Runtime (Extras in the Menue)
Dim FSO As New FileSystemObject
Dim D As File
Dim SF As Folder 'Sourcefolder
Dim TF As Folder 'Targetfolder
Const cSourceFolder = "C:\LocalPath\"
Const cTargetFolder_Basis = "\\...\abc\def\"
Set SF = FSO.GetFolder(cSourceFolder)
If SF Is Nothing Then
MsgBox "Error in SourceFolder """ & cSourceFolder & """.", vbCritical + _
vbOKOnly, "Error"
End If
For Each D In SF.Files
If Left(D.Name, 3) = "LEG" Then
Select Case LCase(Right(D.Name, Len(D.Name) - InStrRev(D.Name, ".")))
Case "xlsx" ', "xlsm"
Set TF = Nothing
Set TF = FSO.GetFolder(cTargetFolder_Basis & Left(D.Name, 6))
If TF Is Nothing Then Debug.Print "Error with " & cTargetFolder_Basis & Left(D.Name, _
5)
'At this point should happen the checking for a existing file in the folder and moving the file to the Archive folder
FSO.MoveFile D.Path, TF.Path & "\" & D.Name
End Select
End If
Next
Set SF = Nothing
Set TF = Nothing
End Sub
Has somebody an idea how i can implement the needed checking before Upload?
Thanks for your help in advance
Simeon
Last edited: