Solved

Finding a Hidden File in Excel VBA

Posted on 2010-08-26
3
255 Views
Last Modified: 2013-11-26
I have this line of code in Excel's VBA:

x = Len(Dir$(varFileName))

Unfortunately, x = 0 if the file's attributes (i.e., varFileName) are set to hidden.  How can I keep the file hidden, yet get the true value for x?
0
Comment
Question by:HaimD
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
calacuccia earned 500 total points
Comment Utility
x = Len(Dir$(varFileName, vbHidden))
0
 

Author Closing Comment

by:HaimD
Comment Utility
Simply-easily perfect!  Learned something new!  Thanks
:)
0
 
LVL 17

Expert Comment

by:calacuccia
Comment Utility
You're welcome.
From VBA Help, the attributes you can use for Dir$

Constant Value Description
vbNormal 0 (Default) Specifies files with no attributes.
vbReadOnly 1 Specifies read-only files in addition to files with no attributes.
vbHidden 2 Specifies hidden files in addition to files with no attributes.
VbSystem 4 Specifies system files in addition to files with no attributes. Not available on the Macintosh.
vbVolume 8 Specifies volume label; if any other attributed is specified, vbVolume is ignored. Not available on the Macintosh.
vbDirectory 16 Specifies directories or folders in addition to files with no attributes.
vbAlias 64 Specified file name is an alias. Available only on the Macintosh.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

728 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

10 Experts available now in Live!

Get 1:1 Help Now