Solved

vba fso

Posted on 2013-06-11
2
374 Views
Last Modified: 2013-06-11
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
Comment
Question by:Rayne
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 39238787
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
 

Author Comment

by:Rayne
ID: 39238910
Thanks Patrick :)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you how to use shortcut menus in the Access run-time environment.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question