Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding hidden or system files containing ~ using Dir() in VBA

Tags:

excel

vba

I'm trying to rename a series of files for SharePoint that contain illegal characters such as #, &, ~, etc. I modified the code from this site to find the files/folders to rename. When I run the following command

strTemp = Dir(strFolder & "*~*", vbHidden)

(or with any other attributes for that matter) I get a huge list of files in the directory that do not contain a ~, and yet it still does not seem to find some files that contain an initial ~ (such as temporary files caused by editing a document that were never deleted).

Anybody out there know how to locate those files?

like image 896
ecksc Avatar asked Oct 19 '25 03:10

ecksc


1 Answers

You don't need to replace the constants with the number 6. To combine attributes you can add them using +, for example:

strTemp = Dir(strFolder & "*~*", vbHidden + vbSystem)
like image 187
Jim Avatar answered Oct 21 '25 01:10

Jim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!