Filter string in GetOpenFilename method  
Author Message
armasha





PostPosted: Visual Basic for Applications (VBA), Filter string in GetOpenFilename method Top

L/G,

I wrote the macro below in order to be open particular type of files in Excel. In fact it is a text file, but it has always the same name, let's call it "AAAA". I would like to have a filter in order to be able to see only this file in folder when i use GetOpenFilename. But the filter string in GetOpenFilename method doesn't work. The code shows all the files in the current directory. What is the right filter string

Any help will be appreciated.

Here is the code


Private Sub OpenAAAA()

Dim strAaaaFullFileNm As String

Application.StatusBar = "Opening AAAA"

ChDrive ThisWorkbook.Path
ChDir ThisWorkbook.Path

strAaaaFullFileNm = Application.GetOpenFilename("AAAA file, AAAA", 1, "Open AAAA", , False)

Workbooks.OpenText Filename:= _
strAaaaFullFileNm _
, Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=True, _
Comma:=True, Space:=True, Other:=True, TrailingMinusNumbers:=True
strAaaaName = ActiveWorkbook.Name

End Sub



Microsoft ISV Community Center Forums3  
 
 
Navajo





PostPosted: Visual Basic for Applications (VBA), Filter string in GetOpenFilename method Top

Hi

You could use the File Dialog object instead -

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.InitialFileName = "AAAA.txt"
.Title = "Open AAAA file"
.Filters.Add "AAAA files", "*.txt"

If .Show = True Then
Workbooks.OpenText .SelectedItems(1)
End If
End With


 
 
armasha





PostPosted: Visual Basic for Applications (VBA), Filter string in GetOpenFilename method Top

Thank you, Navajo.