CodeItBetter Programming Another VB Programming Blog

How to get the file path for the selected file using Common Dialog control

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'File/Folder Handling - How to get the file path for the selected file using Common Dialog control
Option Explicit
 
'Insert a Common Dialog Control on your form and add the following code:

Private Sub Command1_Click()
    With CommonDialog1
        .Flags = cdlOFNNoValidate
        .FileName = "*.*"
        .ShowOpen
        Debug.Print .FileName 'Filename with Full path
        Debug.Print .FileTitle 'Filename without path
        Debug.Print returnPathOfFile(.FileName) 'only File path
    End With
End Sub
 
Private Function returnPathOfFile(ByVal strFile As String) As String
    returnPathOfFile = Left(strFile, InStrRev(strFile, "\"))
End Function
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.