Consulting

Results 1 to 11 of 11

Thread: Run-Time error -- GetOpenFilename / Open Browse Box

  1. #1

    Run-Time error -- GetOpenFilename

    I am gettting an error:

    Method 'GetOpenFilename' of object '_Application' failed

    The strange thing is that it works fine on a PC. Same versions of Office.

    Here is my code:

    [VBA]Dim fname As Variant
    Dim FNUM As Long
    Dim SLINE As String
    Dim I As Long
    Dim RW As Long
    fname = Application.GetOpenFilename(filefilter:="TEXT FILES (*.TXT), *.TXT")
    If fname <> False Then
    FNUM = FreeFile()
    Open fname For Input As #FNUM
    Do While Not EOF(FNUM)
    Line Input #FNUM, SLINE
    RW = RW + 1
    For I = 1 To Len(SLINE)
    Cells(RW, I).Value = Mid(SLINE, I, 1)
    Next
    Loop[/VBA]

  2. #2

    Open browse box

    How can I get an Open File Dialog Browse box using VBA in Excel on a Mac???

    I try the following but I get an error:

    fname = Application.GetOpenFilename(filefilter:="TEXT FILES (*.TXT), *.TXT")

    and

    fn = Application.GetOpenFilename(filefilter:="EXCEL FILES (*.XLS), *.XLS")

    both produces errors.

    Works fine on a PC but not on a Mac.

    Thanks!!

  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,897
    Location
    How about just using the native OpenFileDialog dialog box? I'm not aware of a Mac issue with this. If need be, we can move this topic to the Mac Help forum.

  4. #4
    Could you give me the syntax for the OpenFileDialog?

    Thanks!

  5. #5
    VBAX Regular vonpookie's Avatar
    Joined
    Jun 2004
    Location
    Are we there yet?
    Posts
    74
    Location

  6. #6
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,897
    Location
    Stick to ONE thread please. http://vbaexpress.com/forum/showthread.php?t=6144

    And always note your cross posts.

  7. #7
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    268
    Location
    The strange thing is that it works fine on a PC. Same versions of Office.
    You on a Mac? (Although the Office versions cannot be the same.) Arguments for GetOpenFilename are different on Mac.

  8. #8
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    268
    Location
    From the Help File:

    FileFilter Optional Variant. A string specifying file filtering criteria.
    In Windows, this string consists of pairs of file filter strings followed by the MS-DOS wildcard file filter specification, with each part and each pair separated by commas. Each separate pair is listed in the Files of type drop-down list box. For example, the following string specifies two file filters, text and addin: "Text Files (*.txt),*.txt,Add-In Files (*.xla),*.xla".

    ....

    On the Macintosh, this string is a list of comma-separated file type codes (for example, "TEXT,XLA5,XLS4"). Spaces are significant and shouldn't be inserted before or after the comma separators unless they're part of the file type code. If omitted, this argument defaults to all file types.


    Note that file type codes are rather irritating since almost all interesting file types in Excel are TEXT, which does not allow you to distinguish between .txt, .csv, etc...

    Edit: Please note that I was the one who moved / merged / deleted your threads. Also, you should advise those reading your thread on MrExcel that you have cross-posted here.

  9. #9
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,897
    Location
    I wonder which line is erroring out?

    What if you changed this ..

    [vba]If fname <> False Then[/vba]

    .. to this ..

    [vba]If TypeName(fname) <> "Boolean" Then[/vba]

    Here is a working example ..

    [vba]Option Explicit

    Sub TestGOFN()
    Dim fname
    fname = Application.GetOpenFilename("Text Files (*.txt), *.txt")
    If TypeName(fname) = "Boolean" Then
    MsgBox "Pressed cancel."
    Else
    MsgBox "Confirmed file " & fname & "."
    End If
    End Sub[/vba]

  10. #10
    Thanks for the help. But I get the same error as before.

  11. #11
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    268
    Location
    Please see my post #8 above. You cannot specify filefilter the same way on Mac as you do on Windows. That is where your error is coming from.

Posting Permissions

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