Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to check if a file exists on a network drive 1

Status
Not open for further replies.

Vamphyri

Technical User
Mar 18, 2005
60
US
Hi All!

Really simple one for you. The stopwatch is running.

Is there a way to have VBA check to see if an external file exists? Not to open, just to see if it exists. If not, how would I code a "close/exit" for the program?

Program is excel 2000.

Hopefully this isn't too simple for all you VBA-gurus.

Thanks a bunch for any tips or ideas.

Chris


In the immortal words of Socrates, who said:
"I drank what?
 
see if an external file exists
Have a look at the Dir function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Vamphyri said:
The stopwatch is running
And 3 minutes isn't bad!

Does PHV just sit waiting for the questions to come in?!!
Only joking!

Anyway, another thing to look into would be the FileSystemObject object.

;-)
If a man says something and there are no women there to hear him, is he still wrong? [ponder]
How do I get the best answers?
 
Thanks guys!

Upon rereading my original post I found it did not express my question as i really wanted it.

Once I check to see if a file exists I would need the macro to do 1 of 2 things (dependent upon whether or not the "test" file was found):
1: If found continue to load the requested workbook (the one where this macro will reside, or
2: Close the workbook if the "test" file is NOT found.

Any additional information would be helpful.

FYI, I am trying to use this feature to "bulk up" our internal security on a couple of workbooks. And, as Excel is not exactly a secure environment, this is what I came up with. Not the best approach surely, but just "one man's dream". :)

Thanks again

Chris

PS PHV...DO you just sit around waiting for the questions to roll in or what? You are ALWAYS one of the first respondents. I figure if you're NOT one of the first... you must have been taking a break.


In the immortal words of Socrates, who said:
"I drank what?
 
A starting point:
If Dir("\\path\to\test") = "" Then
Application.Quit
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Excellent!!!

Worked just as I saw it on the TV.

A star for you.

Probably the easiest star you've earned by far, but helped a newbie out a ton.

Thanks again.


In the immortal words of Socrates, who said:
"I drank what?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top