Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ANother FSO Create Folder Issue

Posted on 2013-12-18
2
Medium Priority
?
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Assisted Solution

by:MacroShadow
MacroShadow earned 1000 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 81

Accepted Solution

by:
byundt earned 1000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

604 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