Consulting

Results 1 to 6 of 6

Thread: Error 438 FileDialog Filters.Add

  1. #1

    Error 438 FileDialog Filters.Add

    This is my code:

    [vba]
    Sub test()
    Dim dlg As FileDialog
    Set dlg = Application.FileDialog(msoFileDialogFilePicker)
    With dlg
    .InitialFileName = "C:\"
    .Title = "Choose the file."
    .Filters.Clear .Filters.Add "Excel", "*.xls"
    .Show
    End With
    End Sub
    [/vba]
    WHY I OBTAIN A ERROR 438 IN THIS LINE?
    .Filters.Add "Excel", "*.xls"

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    If you really have these two statements on a single line ...

    [VBA]
    .Filters.Clear .Filters.Add "Excel", "*.xls"
    [/VBA]


    ... try making two lines.

    [VBA]
    Option Explicit
    Sub test()
    Dim dlg As FileDialog

    Set dlg = Application.FileDialog(msoFileDialogFilePicker)

    With dlg
    .InitialFileName = "C:\"
    .Title = "Choose the file."
    .Filters.Clear
    .Filters.Add "Excel", "*.xls"
    .Show
    End With
    End Sub
    [/VBA]

    This seems to work for me

    Paul

  3. #3
    Thanks.
    NO, but it was just an edition error

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Are you trying to open a file browser that only shows excel files?

    Paul's solution works for me too.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    Thanks.
    THE SAME CODE
    In my version Excel 2007 >> OK
    In my version Excel 2003 >> ERROR 438
    In my version Excel 2000 >> FileDialog not exists

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I have 2003 and it works without error.....
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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