Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Verify a directory exists

I hope someone can help me with this. I am using VBA in
Excel XP with Windows 2000.

I am working with a legacy program in which the user
supplies a network path (e.g. \\col-gs1\subdir\temp\).

I cannot change the program other than to add a subroutine
that will verify that the user-supplied path is valid and
actually exists. This path is also typically empty, so I
can't look for any particular file either.

I know there are better ways to accomplish getting a path
from a user, but I must work within boss's constraints.

Your example code would be most appreciated. Thanks in
advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Verify a directory exists

You can use this function

Function DirectoryExist(sstr As String)
'Tom Oglivy
Dim lngAttr As Long
DirectoryExist = False
If Dir(sstr, vbDirectory) < "" Then
lngAttr = GetAttr(sstr)
If lngAttr And vbDirectory Then _
DirectoryExist = True
End If
End Function

and use it like this

Dim Dirname As String
Dirname = "C:\MyDir"
If Not DirectoryExist(Dirname) Then
'.........................
Else
'............................
End If

--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl



"MacroMan" wrote in message ...
I hope someone can help me with this. I am using VBA in
Excel XP with Windows 2000.

I am working with a legacy program in which the user
supplies a network path (e.g. \\col-gs1\subdir\temp\).

I cannot change the program other than to add a subroutine
that will verify that the user-supplied path is valid and
actually exists. This path is also typically empty, so I
can't look for any particular file either.

I know there are better ways to accomplish getting a path
from a user, but I must work within boss's constraints.

Your example code would be most appreciated. Thanks in
advance.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Verify a directory exists

You can force the directory to exist using a windows API
call:

Private Declare Function MakeSureDirectoryPathExists
Lib "imagehlp.dll" (ByVal lpPath As String) As Long

The lpPath argument can be a mapped network volume or its
UNC name, it should end with \.

If you do not want to force it to exist,

Private Declare Function PathFileExists Lib "shlwapi.dll"
Alias "PathFileExistsA" (ByVal pszPath As String) As Long

for a directory, pszPath must end with \.

-----Original Message-----
I hope someone can help me with this. I am using VBA in
Excel XP with Windows 2000.

I am working with a legacy program in which the user
supplies a network path (e.g. \\col-gs1\subdir\temp\).

I cannot change the program other than to add a

subroutine
that will verify that the user-supplied path is valid and
actually exists. This path is also typically empty, so I
can't look for any particular file either.

I know there are better ways to accomplish getting a path
from a user, but I must work within boss's constraints.

Your example code would be most appreciated. Thanks in
advance.

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Verify a directory exists

Read help for FolderExists Method.

Regards Eric Bentzen
(remove nospam to reply)

"MacroMan" skrev i en meddelelse
...
I hope someone can help me with this. I am using VBA in
Excel XP with Windows 2000.

I am working with a legacy program in which the user
supplies a network path (e.g. \\col-gs1\subdir\temp\).

I cannot change the program other than to add a subroutine
that will verify that the user-supplied path is valid and
actually exists. This path is also typically empty, so I
can't look for any particular file either.

I know there are better ways to accomplish getting a path
from a user, but I must work within boss's constraints.

Your example code would be most appreciated. Thanks in
advance.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to verify that 3 cells are equal Scott Excel Worksheet Functions 6 April 2nd 23 06:36 PM
Cannot verify XNPV with PV or HP-12C ncw Excel Worksheet Functions 4 May 9th 09 12:35 AM
Verify Analysis ToolPak with VBA Horatio J. Bilge, Jr. Excel Discussion (Misc queries) 11 January 21st 09 09:56 PM
Verify email Sandee Excel Discussion (Misc queries) 1 February 9th 05 04:01 PM
Several Dates -Verify zeek Excel Worksheet Functions 4 January 16th 05 01:31 PM


All times are GMT +1. The time now is 07:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"