Solved

vba fso

Posted on 2013-06-11
2
354 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now