• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

vba fso

Hello,

Need a robust vba code that does this.

There is a network folder called gdfgf/fdsfsdf which has a particular csv file.
1.      Create a folder (if it doesn’t exist in C drive by the name: C:\newTemp
2.      Copy the target csv from the network folder and dump it in the newly created folder (C:\newTemp)
3.      Do some stuff with the csv (code not needed for this step)
4.      Delete the folder that has the csv

Thank you
0
Rayne
Asked:
Rayne
1 Solution
 
Patrick MatthewsCommented:
Assuming your user acct has the right permissions...


Dim fso, fil, fld

Set fso = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

Set fil = fso.GetFile("\\servername\share\folder\subfolder\blah.csv")
' Set fil = fso.GetFile("\\servername\c$\folder\subfolder\blah.csv")

If Err <> 0 Then
    MsgBox "blah.csv does not exist"
Else
    Set fld = fso.GetFolder("c:\newTemp")
    If Err <> 0 Then fso.CreateFolder("c:\newTemp")
    fil.Copy "c:\newTemp\blah.csv", True
    ' do stuff to file
    fld.Delete True
End If

Set fil = Nothing
Set fld = Nothing
Set fso = Nothing

On Error GoTo 0

Open in new window

0
 
RayneAuthor Commented:
Thanks Patrick :)
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now