+ Reply to Thread
Results 1 to 13 of 13

OPEN.DIALOG and GetOpenFilename commands not working

  1. #1
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Rhode Island
    MS-Off Ver
    Excel for Mac 2011 and 2007 on PC
    Posts
    265

    OPEN.DIALOG and GetOpenFilename commands not working

    I have been fighting between Visual Basic and XLM approaches to create a macro that can open many similar fixed width text files that have no delimiters so i don't have to go through the tedious import wizard on every one.

    i have got the macros working when i type in the path to the file but i cannot get a function that allows me to choose a file from a dialogue box.

    visual basic keeps saying method failed when i try

    [/CODE] myfile = Application.GetOpenFilename("Text Files,*.txt")Applications [/CODE]

    (sorry for a forum that has rules you are supposed to set off code they seem to make it impossible to figure out how to do that. i can't find a glyphic to click or a FAQ that tells me how.)

    throws the following error:
    Run-time error '1004':
    Method 'GetOpenFilename' of object '_Application' failed

    I don't know where you find tutorials on syntax and parameters with Visual Basic calls such as GetOpenFilename (for instance i have no idea why it takes the prefix Application. and whether other prefixes are possible) although in the thread seeking help finding this solution on the visual basic side, someone offered me the code that is throwing the error.

    and when i went back to my XLM documentation and tried OPEN.DIALOG() instead of getting a dialog box it seems to be making a call to open the active document and then returns an error because a document with the same name is already open.

    anyone know a way around these problems.

    thanks

    brian

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,346

    Re: OPEN.DIALOG and GetOpenFilename commands not working

    Are you using Visual Basic (VB), or writing a macro in Visual Basic for Applications (VBA)? If you are using VB, then you need to set a reference to Excel and create an excel application object, which will then have the .GetOpenFilename method
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: OPEN.DIALOG and GetOpenFilename commands not working

    Hi riwiseuse

    If you're using the Mac as your profile indicates, see this link...notice the Notes about the Mac half way down the discussion.
    http://www.rondebruin.nl/mac/mac015.htm
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Rhode Island
    MS-Off Ver
    Excel for Mac 2011 and 2007 on PC
    Posts
    265

    Re: OPEN.DIALOG and GetOpenFilename commands not working

    Quote Originally Posted by Bernie Deitrick View Post
    Are you using Visual Basic (VB), or writing a macro in Visual Basic for Applications (VBA)? If you are using VB, then you need to set a reference to Excel and create an excel application object, which will then have the .GetOpenFilename method
    Not sure what i am writing in. i never got visual basic from the very beginning. i still use XLM whenever possible. I recorded a macro in Excel and then opened it in the Visual Basic Editor so i have no idea if the is VB or VBA.

    So Application refers to the active application? so basically this is telling Excel to GetOpenFilename?

    and any idea why this command keeps throwing an error when i believe - even though i don't understand why - that my code should be correctly entered to get a open dialogue box?

    thanks

  5. #5
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Rhode Island
    MS-Off Ver
    Excel for Mac 2011 and 2007 on PC
    Posts
    265

    Re: OPEN.DIALOG and GetOpenFilename commands not working

    Quote Originally Posted by jaslake View Post
    Hi riwiseuse

    If you're using the Mac as your profile indicates, see this link...notice the Notes about the Mac half way down the discussion.
    http://www.rondebruin.nl/mac/mac015.htm
    read that page you linked and i still am not clear on what code i am supposed to type to get this macro to ask me for a dialogue box to choose what file i want it bring to the import wizard.

    when i simply enter a path, the recorded macro works perfectly, but i cannot figure out how to get the macro to ask me for the input of a file from a finder dialog box to populate a filename variable.

    (or in the XLM variety I was hoping to enter the command as a parameter of the OPEN.TEXT() function but i cannot even get OPEN.DIALOG() to run on its own.)

    I have examples of the code from the macro i recorded from the Excel Virtual Basic Editor but I do not know how to post that denoted as code which the forum prefers. if anyone can tell me how to do that i can post the code.

    thanks,

    brian

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,346

    Re: OPEN.DIALOG and GetOpenFilename commands not working

    That would be VBA then.

    Try just this, since Macs can't use the filter

    Please Login or Register  to view this content.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: OPEN.DIALOG and GetOpenFilename commands not working

    Hi brian

    See the Pound Sign (#) Icon in the Header Row? When you Click that you'll get this.
    CODE][/CODE
    Paste the Code between the two middle Braces.

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Rhode Island
    MS-Off Ver
    Excel for Mac 2011 and 2007 on PC
    Posts
    265

    Re: OPEN.DIALOG and GetOpenFilename commands not working

    Quote Originally Posted by Bernie Deitrick View Post
    That would be VBA then.

    Try just this, since Macs can't use the filter

    Please Login or Register  to view this content.
    that is what i tried and it throws and error:
    Run-time error '1004':
    Method 'GetOpenFilename' of object '_Application' failed

    here is the code i used which just extends that slightly. got it cleaned up after the macro record:
    Please Login or Register  to view this content.
    and if i run the same code but just put a pathway to a file in place of the
    Please Login or Register  to view this content.
    e.g.
    Please Login or Register  to view this content.
    then it works just fine. opens the file. i am simply not able to call the dialogue box so i can choose different files. and have had equally no success with OPEN.DIALOGY form the XLM macro language which ought to do it also.

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,346

    Re: OPEN.DIALOG and GetOpenFilename commands not working

    Did you try it with no filter:

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Rhode Island
    MS-Off Ver
    Excel for Mac 2011 and 2007 on PC
    Posts
    265

    Re: OPEN.DIALOG and GetOpenFilename commands not working

    by no filter, do you me without the if IF testing for false? or . . . . not sure what you mean by filter?

  11. #11
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Rhode Island
    MS-Off Ver
    Excel for Mac 2011 and 2007 on PC
    Posts
    265

    Re: OPEN.DIALOG and GetOpenFilename commands not working

    PS i did try it without the IF function and got the same error but maybe that is not what you are referring to.

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: OPEN.DIALOG and GetOpenFilename commands not working

    Bernie is referring to this:
    Please Login or Register  to view this content.
    rather than this:
    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  13. #13
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Rhode Island
    MS-Off Ver
    Excel for Mac 2011 and 2007 on PC
    Posts
    265

    Re: OPEN.DIALOG and GetOpenFilename commands not working

    got it. so that works in visual basic (or is it visual basic for applications). not sure why it doesn't like those filters but works like a champ with them gone.

    meanwhile i went back to XLM and this works if I go to macros and step in or run the program but throws an error if I call it with a command option key.

    Please Login or Register  to view this content.
    the error is the one reported above where somehow it takes the routine as an effort to open the document that is already open and active, i.e. the document containing the macro.

    although i've checked and rechecked the target in the INSERT>NAME>DEFINE command this must have more to do with some problem releasing the command option combination i set (shift F) or some anamoly resulting from calling the macro with the key combination instead of just chosing TOOLS>MACRO>MACROS and the selecting the one i want to run (this list includes both XLM and VB macros) and then clicking "RUN" to the right where the various options "STEP-IN" etc. show up. If i do it that way it runs fine but not with the command key combo which apparently was my problem with the XLM approach all along. go figure.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] GetOpenFilename to extract date, modify for use in GetSaveAsFilename (not working)
    By Hyflex in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-20-2015, 05:22 PM
  2. [SOLVED] loop getOpenFilename until correct file is picked not working
    By mongoose36 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-16-2014, 12:39 PM
  3. GetOpenFilename Not Working
    By Jmk326 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-20-2013, 02:21 AM
  4. [SOLVED] MACRO: Using predefined path in dialog box for GetOpenFilename
    By AnnieMcken in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-16-2013, 08:17 AM
  5. Help with implementing GetOpenFileName dialog box in Data Import
    By DarkDevin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-24-2011, 10:44 AM
  6. Substitute GetOpenFilename File Open Window with automated command
    By RBdad in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-03-2011, 07:09 PM
  7. working on a selected file via GetOpenFilename
    By periro16 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-21-2005, 08:52 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1