Forum

FolderExists functi...
 
Notifications
Clear all

FolderExists function of the FileSystemObject

5 Posts
3 Users
0 Reactions
98 Views
(@ppsurge)
Posts: 3
Active Member
Topic starter
 

Hi Experts,

I am having n number of rows with different path in one particular column. I build a macro to check all the path and if the folders are available in the specified path then will color the cell in grey and find out the number of files inside that particular folder in the next cell. If the folder is not available then I will highlight the rows in yellow color. 

Here my concern is the Folderexists function of the FileSystemObject is not working properly and I am not getting the proper output. Sometimes even the folder is not available, it will highlight in grey color and return the file count and vice versa (folder is available but its highlighted with the yellow color). One more information is folders which i need to check are available in the mapped network local drive (Sharepoint).

Please give your suggestion to resolve this issue.

Regards,
Dhans.

Please find blow the code which i am using:

If fso.FolderExists(sourcepath) Then
r(, 165).Value = fso.GetFolder(sourcepath).Files.Count
r(, 164).Interior.Color = RGB(200, 200, 200)
Else
r(, 164).Interior.Color = vbYellow
End If

 
Posted : 28/09/2021 4:19 am
(@purfleet)
Posts: 412
Reputable Member
 

Please add a workbook example to see what we are looking at

Personally i dont use FileSystemObject when checking if folders exist, i find it much easier to use

if len(dir(filepath & filename,vbdirectory) = 0

in a loop, espeically if the folders/files are listed in the workbook

 
Posted : 28/09/2021 1:56 pm
(@debaser)
Posts: 836
Member Moderator
 

I'd suspect the problem lies elsewhere (in the code you didn't post) since I can't see how you'd get a file count for a non-existent folder.

 
Posted : 29/09/2021 4:05 am
(@ppsurge)
Posts: 3
Active Member
Topic starter
 

Thanks for the quick reply Purfleet. I will try and let you know the updates.

 
Posted : 29/09/2021 7:54 am
(@ppsurge)
Posts: 3
Active Member
Topic starter
 

Thanks Velouria. The code which I pasted here is only place where I using the file count. 

 
Posted : 29/09/2021 8:02 am
Share: