VBA/Excel/Access/Word/File Path/Path

Материал из VB Эксперт
Перейти к: навигация, поиск

Determining whether a path exists

   <source lang="vb">

Function PathExists(pname) As Boolean

   Dim x As String
   On Error Resume Next
   x = GetAttr(pname) And 0
   If Err = 0 Then PathExists = True _
     Else PathExists = False

End Function

</source>
   
  


Get file name from a path name

   <source lang="vb">

Public Sub GetFileNameTest()

 MsgBox GetFileName("C:\text.txt")

End Sub Function GetFileName(ByVal Path As String) As String

 Dim I As Integer
 
 For I = Len(Path) To 1 Step -1
   If Mid(Path, I, 1) = Application.PathSeparator Or Mid(Path, I, 1) = ":" Then Exit For
 Next I
  
 GetFileName = Right(Path, Len(Path) - I)

End Function

</source>
   
  


Get the Path Separator

   <source lang="vb">

Sub PathSeparator()

   MsgBox Application.PathSeparator

End Sub

</source>