How to check output folder has been created in the network path?using VBA programming

H

Harinath

On a spreadsheet a button "Check Status" is added
Pressing the button will trigger a simple check as to whether the output folder has been created in the network path.
- If that folder does not exist, a reply "In progress" or similar appears.
- If that folder exists, a hyperlink to the folder's network path appears; clicking the link will open a browser to that location,

Please put some light on this problem to solve.

Thanks
Harinath
 
A

AA2e72E

Put this line in the Declaration section

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

call this sub with the name of your output folder

sub aa(byval outputfolder
MakeSureDirectoryPathExists outputfolde
end su

The output folder will be created if it does not exist.
 
H

Harinath

Thanks for the info

But in my case the code should check that the folder is created in the path (or like presence of the folder in the network path)
It should not create the folder

If the folder exists a popup message should provide a path,by clicking that the path the browser should open

thank
harinath
 
B

Bob Phillips

Two things.

The directory name must end with a \.

If you want to know whether it existed before the code was executed use
something like

Dim sFolder As String
Dim sDir As String
Dim ans
sFolder = "C:\myDir"
On Error Resume Next
sDir = Dir(sFolder, vbDirectory)
If sDir = "" Then
If (GetAttr(sFolder) And vbDirectory) = vbDirectory Then
MakeSureDirectoryPathExists sFolder & "\"
End If
End If


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
A

AA2e72E

This API returns 0 is a folder does not exist and non zero when it does

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

Bob Phillips

No it doesn't, it returns 0 if it fails, that is it doesn't create one or
more folders, 1 if all is well.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

AA2e72E said:
This API returns 0 is a folder does not exist and non zero when it does.

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