Consulting

Results 1 to 10 of 10

Thread: Solved: Sloved:Why GetOpenFilename not working

  1. #1

    Solved: Sloved:Why GetOpenFilename not working

    Hi all,

    Why IsArray(Nfilename) always return false and Nfilename(1) get error msg "type dismatch)" in Beneath code at office2000:

    Sub Macro1()
    Dim Nfilename As Variant
    Nfilename = Application.GetOpenFilename("Excel Files (*.xls), *.xls", , , , True)
    if not IsArray(Nfilename) then MsgBox "No files selected")
    s=Nfilename(1)
    End Sub

    thks!
    Last edited by willin; 07-20-2007 at 03:38 AM. Reason: Sloved

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Apart from the superfluous ), it all works fine for me.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Quote Originally Posted by xld
    Apart from the superfluous ), it all works fine for me.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Post an offending workbook so we can see it.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Quote Originally Posted by willin
    s=Nfilename(1)
    What is the 's' variable's type? Variant? String?

    And as XLD said, please post a workbook with the error so we can replicate it.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  6. #6
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    change to

    Sub Macro1()
    Dim Nfilename As Variant
    Nfilename = Application.GetOpenFilename("Excel Files (*.xls), *.xls", , , , True)
    If Not IsArray(Nfilename) Then
        MsgBox "No files selected"
        Exit Sub
    End If
        s = Nfilename(1)
    End Sub
    The error occurred if the user clicks Cancel in the dialogue box, NFilename isn't an array at that point, so NFilename(1) is meaningless.

    p45cal
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  7. #7
    Quote Originally Posted by p45cal
    change to
    The error occurred if the user clicks Cancel in the dialogue box, NFilename isn't an array at that point, so NFilename(1) is meaningless.
    p45cal
    No,
    I mean even if I selected files, IsArray() still return false.


    I had done lot of debug , now I got the root cause : If there hv error on condition format formula in opening any files, then it will be happen.

    Pls find attached file, if you remove the Cell"G34" condition format or you change H34 from 0 to any digital but zero. then macro will fine. otherwise the code always return error whatever you select files or not.
    But I don't know if it fine in office2003.

    But I need the condition format remain allow h34=0,
    How Can I do to solve this problem is macro?

    Thks!

  8. #8
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,875
    see:
    www . excelforum.com/archive/index.php/t-497214.html

    (note that the url above has had to be mangled by me as this is only my second post to this forum and until I've posted 5 times I'm not allowed to include links, so you'll have to unmangle it)
    search for the text 'tested this' where a variety of solutions/workarounds are suggested for this bug.

    p45cal
    Last edited by p45cal; 07-20-2007 at 02:36 AM.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  9. #9
    Thks, Let me try ....

  10. #10
    Now I got the solution:
    3. scroll cf's cell(s) are no longer in view.
    4. activate another worksheet then it suceeds under all conditions.

    so some code need added before "getopenfilename" to check if related action is required.

    Helper cell isn't suit my situation. there some difference on cf's:
    my case due to cf's formulas result is error (div 0) but not used wf's.

    Thks p45cal given the good url!
    Thks all of u for responding!
    Last edited by willin; 07-20-2007 at 05:52 AM.

Posting Permissions

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