troubleshooting Question

VBA Path Not Found

Avatar of Richard Turner
Richard Turner asked on
* Excel TableVBA
3 Comments1 Solution29 ViewsLast Modified:
I want to look in a folder and pull a list of all the files in that folder.
I found a snippet of code that does this and it sometimes works and sometimes not.
I think the issue may be because I need the path to be relative.
Here's the bit of relevant code.  I get a 'path not found' runtime error on the last line.
The path in StrLoc is "..\Analysis & Testing\Analysis Reports\"

Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object

StrLoc = "..\" & Right(StrLoc, n) & "\Analysis Reports\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(StrLoc)

Help would be appreciated.  I cannot use a fixed path string as it changes depending on the user.
But I can say that the Excel file this is in is inside Analysis & Testing and so Analysis Reports is therefore a subfolder and this structure will always be the same.
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros