![]() |
Return file name only from FileDialog
Hi,
I'm looking for a way to return only the File Name from the FileDialog object. From what I can see I can only return both the full path and file name. I'm open to suggestion of alternative methods other than FileDialog such as an API but again any API examples I have found only return the full path. Has anybody any suggestions on how i could do this? Thanks Paul |
Return file name only from FileDialog
Most would strip out the filename from the fullpathName
sFileName = Right(sFullPathName,Len(sFullPathBName)-InstrRev(sFullPathName,"\")) demo'd from the immediate window: sFullPathName = "C:\MyMainsubFolder\MySecondarySubFolder\Myfile.xl s" ? sFullPathname C:\MyMainsubFolder\MySecondarySubFolder\Myfile.xls sFileName = Right(sFullPathName,Len(sFullPathName)-InstrRev(sFullPathName,"\")) ? sfileName Myfile.xls -- Regards, Tom Ogilvy "PMC1" wrote: Hi, I'm looking for a way to return only the File Name from the FileDialog object. From what I can see I can only return both the full path and file name. I'm open to suggestion of alternative methods other than FileDialog such as an API but again any API examples I have found only return the full path. Has anybody any suggestions on how i could do this? Thanks Paul |
Return file name only from FileDialog
If you import GetOpenFileName (comdlg32.dll), the string to return should be the FileTitle, not the FileName... Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pFILETOOPEN As FILETOOPEN) As Long Private Type FILETOOPEN 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 Private Sub GetFileName() Dim FTO As FILETOOPEN FTO.lStructSize = Len(FTO) FTO.hwndOwner = 0 FTO.hInstance = 0 FTO.lpstrFilter = "Text Files (*.txt)" + Chr$(0) + "*.txt" + Chr$(0) + "All Files (*.*)" + Chr$(0) + "*.*" + Chr$(0) FTO.lpstrFile = Space$(254) FTO.nMaxFile = 255 FTO.lpstrFileTitle = Space$(254) FTO.nMaxFileTitle = 255 FTO.lpstrInitialDir = "C:\" FTO.lpstrTitle = "Select a File..." FTO.flags = 0 If GetOpenFileName(FTO) Then MsgBox "FileName: " + Trim$(FTO.lpstrFileTitle) Else 'Do nothing End If End Sub "PMC1" schreef in bericht ps.com... Hi, I'm looking for a way to return only the File Name from the FileDialog object. From what I can see I can only return both the full path and file name. I'm open to suggestion of alternative methods other than FileDialog such as an API but again any API examples I have found only return the full path. Has anybody any suggestions on how i could do this? Thanks Paul |
All times are GMT +1. The time now is 12:41 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com