Gil
02-23-2011, 12:24 PM
I am using this code to confirm if a Folder exists which confirms with a message box. I would like to copy the path to paste elsewhere but unable to with the message box. Can a text box be used instead.
I tried a few different things but have failed. Any ideas.
Thanks Gil
Option Explicit
Function FileOrDirExists(PathName As String) As Boolean
'Macro Purpose: Function returns TRUE if the specified file
' or folder exists, false if not.
'PathName : Supports Windows mapped drives or UNC
' : Supports Macintosh paths
'File usage : Provide full file path and extension
'Folder usage : Provide full folder path
' Accepts with/without trailing "\" (Windows)
' Accepts with/without trailing ":" (Macintosh)
Dim iTemp As Integer
'Ignore errors to allow for error evaluation
On Error Resume Next
iTemp = GetAttr(PathName)
'Check if error exists and set response appropriately
Select Case Err.Number
Case Is = 0
FileOrDirExists = True
Case Else
FileOrDirExists = False
End Select
'Resume error checking
On Error GoTo 0
End Function
Sub TestItWithWindows()
'Macro Purpose: To test the FileOrDirExists function with Windows
'Only included to demonstrate the function. NOT required for normal use!
Dim sPath As String
'Change your directory here
sPath = "C:\Desktop\Any Name You Like"
'Test if directory or file exists
If FileOrDirExists(sPath) Then
TxtBox sPath & " exists!"
Else
MsgBox sPath & " does not exist."
End If
End Sub
I tried a few different things but have failed. Any ideas.
Thanks Gil
Option Explicit
Function FileOrDirExists(PathName As String) As Boolean
'Macro Purpose: Function returns TRUE if the specified file
' or folder exists, false if not.
'PathName : Supports Windows mapped drives or UNC
' : Supports Macintosh paths
'File usage : Provide full file path and extension
'Folder usage : Provide full folder path
' Accepts with/without trailing "\" (Windows)
' Accepts with/without trailing ":" (Macintosh)
Dim iTemp As Integer
'Ignore errors to allow for error evaluation
On Error Resume Next
iTemp = GetAttr(PathName)
'Check if error exists and set response appropriately
Select Case Err.Number
Case Is = 0
FileOrDirExists = True
Case Else
FileOrDirExists = False
End Select
'Resume error checking
On Error GoTo 0
End Function
Sub TestItWithWindows()
'Macro Purpose: To test the FileOrDirExists function with Windows
'Only included to demonstrate the function. NOT required for normal use!
Dim sPath As String
'Change your directory here
sPath = "C:\Desktop\Any Name You Like"
'Test if directory or file exists
If FileOrDirExists(sPath) Then
TxtBox sPath & " exists!"
Else
MsgBox sPath & " does not exist."
End If
End Sub