VBA/Excel/Access/Word/File Path/Path — различия между версиями

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

Версия 16:33, 26 мая 2010

Determining whether a path exists

 
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



Get file name from a path name

 
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



Get the Path Separator

 
Sub PathSeparator()
    MsgBox Application.PathSeparator
End Sub