Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PWS PWS is offline
external usenet poster
 
Posts: 18
Default GetOpenFilename

Can GetOpenFilename be used to display a dialog box which is filtered
by specific files names, i.e. a filter applied to the file name as
well as the file type?

I know I would only get one file at most per directory, but it would
help users when looking for their file in a very well populated
folder!

PWS

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default GetOpenFilename

I cannot get Excel's GetOpenFileName to filter on the filename, only the
extension.
However, the API version (from the API-Guide) does. Amend the
OFName.lpstrFilter to suit your needs.

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

Private Sub CommandButton1_Click()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail:
Dim OFName As OPENFILENAME
OFName.lStructSize = Len(OFName)
'Set the parent window
OFName.hwndOwner = Application.Hwnd
'Set the application's instance
' OFName.hInstance = App.hInstance
'Select a filter
OFName.lpstrFilter = "Text Files (*Test*.xls)" + Chr$(0) + "*Test*.xls"
+ Chr$(0)
'create a buffer for the file
OFName.lpstrFile = Space$(254)
'set the maximum length of a returned file
OFName.nMaxFile = 255
'Create a buffer for the file title
OFName.lpstrFileTitle = Space$(254)
'Set the maximum length of a returned file title
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = "C:\"
'Set the title
OFName.lpstrTitle = "Open File - KPD-Team 1998"
'No flags
OFName.flags = 0

'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then
MsgBox "File to Open: " + Trim$(OFName.lpstrFile)
Else
MsgBox "Cancel was pressed"
End If
End Sub

NickHK


"PWS" wrote in message
ups.com...
Can GetOpenFilename be used to display a dialog box which is filtered
by specific files names, i.e. a filter applied to the file name as
well as the file type?

I know I would only get one file at most per directory, but it would
help users when looking for their file in a very well populated
folder!

PWS



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
GetOpenFilename Craig[_2_] Excel Programming 4 December 15th 05 04:36 PM
GetOpenFilename Jenny Excel Programming 2 October 22nd 04 01:38 PM
GetOpenFilename Todd Htutenstine Excel Programming 2 May 13th 04 03:14 PM
GetOpenFileName Greg Bloom Excel Programming 2 February 9th 04 04:09 PM
GetOpenFilename Hasan Cansü Excel Programming 0 September 24th 03 01:32 PM


All times are GMT +1. The time now is 05:58 AM.

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"