Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
FileDialog Mike Archer Excel Programming 0 May 28th 06 06:31 PM
using a filedialog box from a dll Paul Excel Programming 2 April 26th 06 04:56 PM
FileDialog to select file Acid-Sky Excel Discussion (Misc queries) 2 September 12th 05 06:53 PM
Using FileDialog or GetOpenFileName To Allow File Creation WhyIsDoug Excel Programming 1 July 28th 05 05:14 PM
FileDialog Help Maynard Excel Programming 0 August 4th 04 01:43 PM


All times are GMT +1. The time now is 09:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"