Felix Atagong
Active Member
- Joined
- Jun 27, 2003
- Messages
- 359
After some parsing, I need to move certain files to a shared network folder, ...but if I haven't logged in before the VBA will give an error that the path does not exist.
I know there is a way to check if the folder is accessible or not but is it possible to prompt for the login and password (or fill these in automatically) so that the macro will proceed?
I use the following script (borrowed from a well-known Excel site):
I know there is a way to check if the folder is accessible or not but is it possible to prompt for the login and password (or fill these in automatically) so that the macro will proceed?
I use the following script (borrowed from a well-known Excel site):
Code:
Sub Move_Certain_Files_To_Folder()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String
FromPath = "C:\E2A"
ToPath = "Z:\edi\reception\" ' or "\\123.456.789.001\edi\reception\" (remote network folder)
FileExt = "EDI_1234_*.*"
If Right(FromPath, 1) <> "\" Then
FromPath = FromPath & "\"
End If
FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "No files in " & FromPath
Exit Sub
End If
Set FSO = CreateObject("scripting.filesystemobject")
FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "FILES TRANSFERRED TO " & ToPath
End Sub