dialog box: Application getopen filename code syntax questio
Eliminate Pivot Table Annoyances
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: dialog box: Application getopen filename code syntax questio

  1. #1
    New Member
    Join Date
    Apr 2002
    Location
    Jason in Boston MA
    Posts
    12
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    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. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #3
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    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

    Kind Regards,
    Ivan F Moala From the City of Sails

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com