![]() |
GetOpenFileName with F*.txt
In a perfect world, I want to have my list of available text files be only
those that start with the letter "F". It appears that Excel (97 in this case) will honor a "*.TXT" but ignores the "F" if I specifiy it as "F*.TXT" Does Excel(97) or any addition permit anything more than just "*.TXT"? -- DRK |
GetOpenFileName with F*.txt
As far as I know, there is no way to do this.
-- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "DRK" wrote in message ... In a perfect world, I want to have my list of available text files be only those that start with the letter "F". It appears that Excel (97 in this case) will honor a "*.TXT" but ignores the "F" if I specifiy it as "F*.TXT" Does Excel(97) or any addition permit anything more than just "*.TXT"? -- DRK |
GetOpenFileName with F*.txt
Excel 2002 introduced an additional dialog - I don't know whether it
supports that filter structure or not, but GetOpenFileName is consistently restrictive in its support through Excel 2003 to the best of my knowledge. for xl2002 or later: Sub Main() 'Declare a variable as a FileDialog object. Dim fd As FileDialog 'Create a FileDialog object as a File Picker dialog box. Set fd = Application.FileDialog(msoFileDialogFilePicker) 'Declare a variable to contain the path 'of each selected item. Even though the path is a String, 'the variable must be a Variant because For Each...Next 'routines only work with Variants and Objects. Dim vrtSelectedItem As Variant 'Use a With...End With block to reference the FileDialog object. With fd .Filters.Add "Excel Files", "*.xls", 1 'Sets the initial file filter to number 2. .FilterIndex = 1 ' Next line does what you want .InitialFileName = "C:\Data6\F*.xls" 'Use the Show method to display the File Picker dialog box and return the user's action. 'The user pressed the action button. If .Show = -1 Then 'Step through each string in the FileDialogSelectedItems collection. For Each vrtSelectedItem In .SelectedItems 'vrtSelectedItem is a String that contains the path of each selected item. 'You can use any file I/O functions that you want to work with this path. 'This example simply displays the path in a message box. MsgBox "The path is: " & vrtSelectedItem Next vrtSelectedItem 'The user pressed Cancel. Else End If End With 'Set the object variable to Nothing. Set fd = Nothing End Sub -- Regards, Tom Ogilvy "DRK" wrote in message ... In a perfect world, I want to have my list of available text files be only those that start with the letter "F". It appears that Excel (97 in this case) will honor a "*.TXT" but ignores the "F" if I specifiy it as "F*.TXT" Does Excel(97) or any addition permit anything more than just "*.TXT"? -- DRK |
GetOpenFileName with F*.txt
It worked for me from the open file dialog in Excel XP.
|
GetOpenFileName with F*.txt
for clarification, after writing the first sentence, I went and test it
using the filedialog object and figured out how to do it (forgot to change the sentence) - so in xl2002 and later you can use that, but the getopenfilename function does not support it in any version. -- Regards, Tom Ogilvy "Tom Ogilvy" wrote in message ... Excel 2002 introduced an additional dialog - I don't know whether it supports that filter structure or not, but GetOpenFileName is consistently restrictive in its support through Excel 2003 to the best of my knowledge. for xl2002 or later: Sub Main() 'Declare a variable as a FileDialog object. Dim fd As FileDialog 'Create a FileDialog object as a File Picker dialog box. Set fd = Application.FileDialog(msoFileDialogFilePicker) 'Declare a variable to contain the path 'of each selected item. Even though the path is a String, 'the variable must be a Variant because For Each...Next 'routines only work with Variants and Objects. Dim vrtSelectedItem As Variant 'Use a With...End With block to reference the FileDialog object. With fd .Filters.Add "Excel Files", "*.xls", 1 'Sets the initial file filter to number 2. .FilterIndex = 1 ' Next line does what you want .InitialFileName = "C:\Data6\F*.xls" 'Use the Show method to display the File Picker dialog box and return the user's action. 'The user pressed the action button. If .Show = -1 Then 'Step through each string in the FileDialogSelectedItems collection. For Each vrtSelectedItem In .SelectedItems 'vrtSelectedItem is a String that contains the path of each selected item. 'You can use any file I/O functions that you want to work with this path. 'This example simply displays the path in a message box. MsgBox "The path is: " & vrtSelectedItem Next vrtSelectedItem 'The user pressed Cancel. Else End If End With 'Set the object variable to Nothing. Set fd = Nothing End Sub -- Regards, Tom Ogilvy "DRK" wrote in message ... In a perfect world, I want to have my list of available text files be only those that start with the letter "F". It appears that Excel (97 in this case) will honor a "*.TXT" but ignores the "F" if I specifiy it as "F*.TXT" Does Excel(97) or any addition permit anything more than just "*.TXT"? -- DRK |
GetOpenFileName with F*.txt
To do this (Filter file lists) you need to use (for Pre xl2002 - nice one Tom!) the GetOpenFileName function from the comdlg32.dll Have a look here for an explanation and code. http://www.xcelfiles.com/comdlg.html -- Ivan F Moala ------------------------------------------------------------------------ Ivan F Moala's Profile: http://www.excelforum.com/member.php...fo&userid=1954 View this thread: http://www.excelforum.com/showthread...hreadid=376812 |
GetOpenFileName with F*.txt
Thanks to you and everyone else who replied. Problem solved.
-- DRK "Ivan F Moala" wrote: To do this (Filter file lists) you need to use (for Pre xl2002 - nice one Tom!) the GetOpenFileName function from the comdlg32.dll Have a look here for an explanation and code. http://www.xcelfiles.com/comdlg.html -- Ivan F Moala ------------------------------------------------------------------------ Ivan F Moala's Profile: http://www.excelforum.com/member.php...fo&userid=1954 View this thread: http://www.excelforum.com/showthread...hreadid=376812 |
All times are GMT +1. The time now is 02:41 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com