![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Location: Jason in Boston MA
Posts: 12
|
I am using the code below to get a filename from the open browser in a userform. I need to specify file type. if anyone knows the correct syntax I would appreciate it.
pidfile = Application.GetOpenFilename("Text Files (*.txt), *.txt") I am looking for files with the following ending "*pid.isd" Thanks jason |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
Hi
I could not figure any way to use wildcards for the filename it's self. You may have to settle for files ending in "isd" or perhaps create a listbox or combobox with a list of files using the filesearch object. Unless someone else has a better suggestion? Tom |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
To use wild card char in the file open
dialog you will have to the Use the Comdlg API (not the OCX) Try this.... Option Explicit 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 Command1_Click() Dim OpenFile As OPENFILENAME Dim lReturn As Long Dim sFilter As String OpenFile.lStructSize = Len(OpenFile) '// Define your wildcard string here sFilter = "my Files (*pid.isd.*)" & Chr(0) & "*pid.isd.*" & Chr(0) OpenFile.lpstrFilter = sFilter OpenFile.nFilterIndex = 1 OpenFile.lpstrFile = String(257, 0) OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1 OpenFile.lpstrFileTitle = OpenFile.lpstrFile OpenFile.nMaxFileTitle = OpenFile.nMaxFile OpenFile.lpstrInitialDir = "C:" OpenFile.lpstrTitle = "My File Open" OpenFile.flags = 0 lReturn = GetOpenFileName(OpenFile) If lReturn = 0 Then '// Do your thing Else '// Do your thing End If End Sub HTH |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|