工程-》引用-》Microsoft Scriping Runtime
Private Sub Command1_Click()
CommonDialog1.Flags = cdlOFNNoLongNames
CommonDialog1.ShowOpen
Dim aaa As New FileSystemObject
MsgBox aaa.GetFileName(CommonDialog1.FileName)
End Sub
Private Sub Command1_Click()
CommonDialog1.Flags = cdlOFNNoLongNames
CommonDialog1.ShowOpen
Dim aaa As New FileSystemObject
MsgBox aaa.GetFileName(CommonDialog1.FileName)
End Sub
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OpenFileName) As Long
Private Type OpenFileName
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
'Purpose : Allows the user to select a file name based on a filter condition
'Inputs : sInitDir The initial directory of the file dialog
' sFileType A file filter string of the form:
' File Title & chr$(0) & Filter String & chr$(0)
' sTitle The dialog title
'Outputs : Returns the select path and file name
'Author : Andrew Baker
'Date : 12/08/2000 13:06
'Notes :
'Revisions :
Function BrowseForFile(sInitDir As String, Optional ByVal sFileType As String, Optional sTitle As String) As String
Dim tFileBrowse As OpenFileName
Const clMaxLen As Long = 254
tFileBrowse.lStructSize = Len(tFileBrowse)
'Select a filter
tFileBrowse.lpstrFilter = sFileType & "All Files (*.*)" & Chr$(0) & "*.*" & Chr$(0)
'create a buffer for the file
tFileBrowse.lpstrFile = String(clMaxLen, " ")
'set the maximum length of a returned file
tFileBrowse.nMaxFile = clMaxLen + 1
'Create a buffer for the file title
tFileBrowse.lpstrFileTitle = Space$(clMaxLen)
'Set the maximum length of a returned file title
tFileBrowse.nMaxFileTitle = clMaxLen + 1
'Set the initial directory
tFileBrowse.lpstrInitialDir = sInitDir
'Set the title
If Len(sTitle) Then
tFileBrowse.lpstrTitle = sTitle
Else
tFileBrowse.lpstrTitle = "Open File"
End If
'No flags
tFileBrowse.flags = 0
'Show the dialog
If GetOpenFileName(tFileBrowse) Then
BrowseForFile = Trim$(tFileBrowse.lpstrFile)
End If
End Function
'Sub Test()
'BrowseForFile "c:\", "Excel File (*.xls)" & Chr$(0) & "*.xls" & Chr$(0), "Open Workbook"
'End Sub
dim l as integer
dim n as string
n=dlg.filename
do
l=instr(n,"\")
n=right(n,len(n)-l)
loop while l>0
msgbox n 'n就是所要的文件名