Solved

ANother FSO Create Folder Issue

Posted on 2013-12-18
2
232 Views
Last Modified: 2013-12-22
Why do I get a Path Not Found error at Set fldr = fs.CreateFolder(sPath & "\rfid\") when I know it's not there...I am trying to create it if it is not there?  The sPath directory is there.

    Set fs = CreateObject("Scripting.FileSystemObject")

    If fs.FolderExists(sPath) = False Then CreateFolder (sPath)
    
    If fs.FolderExists(sPath & "\rfid\") = False Then
        Set fldr = fs.CreateFolder(sPath & "\rfid\")
    End If

Open in new window


Thanks!
0
Comment
Question by:Bob Schneider
2 Comments
 
LVL 26

Assisted Solution

by:MacroShadow
MacroShadow earned 250 total points
ID: 39728282
Works fine for me.

    Dim fs As Object
    Dim fldr As Object
    
    Set fs = CreateObject("Scripting.FileSystemObject")

    If fs.FolderExists(sPath) = False Then fs.CreateFolder (sPath)

    If fs.FolderExists(sPath & "\rfid\") = False Then
        Set fldr = fs.CreateFolder(sPath & "\rfid\")
    End If

Open in new window

0
 
LVL 80

Accepted Solution

by:
byundt earned 250 total points
ID: 39728421
Did you keep track of your path separators? If sPath ends in a path separator, I can understand the error.

The following code is working for me in Excel 2013. I needed to qualify the first CreateFolder statement with fs.CreateFolder(sPath). After testing, I found that I could omit the trailing path separator in \rfid\    So whichever way you find least confusing, make both statements that refer to \rfid the same.
Sub TestFSO()
Dim fs As Object
Dim sPath As String
Dim fldr As Object
sPath = "X:\VBA"    'This is how Brad tested the code

    Set fs = CreateObject("Scripting.FileSystemObject")

    If fs.FolderExists(sPath) = False Then fs.CreateFolder (sPath)
    
    If fs.FolderExists(sPath & "\rfid\") = False Then
        Set fldr = fs.CreateFolder(sPath & "\rfid\")
    End If
End Sub

Open in new window

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

14 Experts available now in Live!

Get 1:1 Help Now