+ Reply to Thread
Results 1 to 8 of 8

Application.GetOpenFileName

  1. #1
    Chris
    Guest

    Application.GetOpenFileName

    When I type this line into the beginning of my macro and then run the macro,
    I am prompted with a file open dialog box. When I select the file to be
    opened and click ok, the dialog box goes away and my file is not opened. Is
    there more code that I have to add to the macro?

  2. #2
    NickHK
    Guest

    Re: Application.GetOpenFileName

    That statement only return the file path/name to you.
    It's then up to you what you do with it.

    Dim retVal as Variant
    dim WB as workbook
    retval=application.getopenfilename()
    if retval=false then exit sub
    set wb=workbooks.open(retval)
    ....etc

    NickHK

    "Chris" <[email protected]> 级糶秎ン穝籇:[email protected]...
    > When I type this line into the beginning of my macro and then run the
    > macro,
    > I am prompted with a file open dialog box. When I select the file to be
    > opened and click ok, the dialog box goes away and my file is not opened.
    > Is
    > there more code that I have to add to the macro?




  3. #3
    Tom Ogilvy
    Guest

    RE: Application.GetOpenFileName

    Dim fname as String, bk as Workbook
    fname = Application.GetOpenfilename()
    if fname <> "False" then
    set bk = Workbooks.Open(fname)
    else
    exit sub
    end if
    msgbox bk.name & " has been opened"

    --
    Regards,
    Tom Ogilvy


    "Chris" wrote:

    > When I type this line into the beginning of my macro and then run the macro,
    > I am prompted with a file open dialog box. When I select the file to be
    > opened and click ok, the dialog box goes away and my file is not opened. Is
    > there more code that I have to add to the macro?


  4. #4
    Chris
    Guest

    RE: Application.GetOpenFileName

    Thanks that worked, but I have one more issue. I would like Excel to prompt
    me with the text import wizzard if need be because my files need to be
    delimited with certain characters or my macro will not work. So after the
    user selects the file to be opened, a text import wizard box pops up asking
    about delimited or fixed width options. Is there a way to do this?

    "Tom Ogilvy" wrote:

    > Dim fname as String, bk as Workbook
    > fname = Application.GetOpenfilename()
    > if fname <> "False" then
    > set bk = Workbooks.Open(fname)
    > else
    > exit sub
    > end if
    > msgbox bk.name & " has been opened"
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Chris" wrote:
    >
    > > When I type this line into the beginning of my macro and then run the macro,
    > > I am prompted with a file open dialog box. When I select the file to be
    > > opened and click ok, the dialog box goes away and my file is not opened. Is
    > > there more code that I have to add to the macro?


  5. #5
    NickHK
    Guest

    Re: Application.GetOpenFileName

    If you recorrd a macro whilst you use the text import, the code generated
    will manage the import.
    You just need to substitute the filename returned from your .GetOpenFilename
    call.

    Also, look at the help for the arguments of GetOpenFilename, because you can
    supply a file filter to only .txt or .csv or whatever you use.

    NickHK

    "Chris" <[email protected]> 级糶秎ン穝籇:[email protected]...
    > Thanks that worked, but I have one more issue. I would like Excel to
    > prompt
    > me with the text import wizzard if need be because my files need to be
    > delimited with certain characters or my macro will not work. So after the
    > user selects the file to be opened, a text import wizard box pops up
    > asking
    > about delimited or fixed width options. Is there a way to do this?
    >
    > "Tom Ogilvy" wrote:
    >
    >> Dim fname as String, bk as Workbook
    >> fname = Application.GetOpenfilename()
    >> if fname <> "False" then
    >> set bk = Workbooks.Open(fname)
    >> else
    >> exit sub
    >> end if
    >> msgbox bk.name & " has been opened"
    >>
    >> --
    >> Regards,
    >> Tom Ogilvy
    >>
    >>
    >> "Chris" wrote:
    >>
    >> > When I type this line into the beginning of my macro and then run the
    >> > macro,
    >> > I am prompted with a file open dialog box. When I select the file to be
    >> > opened and click ok, the dialog box goes away and my file is not
    >> > opened. Is
    >> > there more code that I have to add to the macro?




  6. #6
    Chris
    Guest

    Re: Application.GetOpenFileName

    Good advice, it worked.

    Thanks A lot, really appreciate it.

    "NickHK" wrote:

    > If you recorrd a macro whilst you use the text import, the code generated
    > will manage the import.
    > You just need to substitute the filename returned from your .GetOpenFilename
    > call.
    >
    > Also, look at the help for the arguments of GetOpenFilename, because you can
    > supply a file filter to only .txt or .csv or whatever you use.
    >
    > NickHK
    >
    > "Chris" <[email protected]> 录露录g漏贸露l楼贸路s禄D:[email protected]...
    > > Thanks that worked, but I have one more issue. I would like Excel to
    > > prompt
    > > me with the text import wizzard if need be because my files need to be
    > > delimited with certain characters or my macro will not work. So after the
    > > user selects the file to be opened, a text import wizard box pops up
    > > asking
    > > about delimited or fixed width options. Is there a way to do this?
    > >
    > > "Tom Ogilvy" wrote:
    > >
    > >> Dim fname as String, bk as Workbook
    > >> fname = Application.GetOpenfilename()
    > >> if fname <> "False" then
    > >> set bk = Workbooks.Open(fname)
    > >> else
    > >> exit sub
    > >> end if
    > >> msgbox bk.name & " has been opened"
    > >>
    > >> --
    > >> Regards,
    > >> Tom Ogilvy
    > >>
    > >>
    > >> "Chris" wrote:
    > >>
    > >> > When I type this line into the beginning of my macro and then run the
    > >> > macro,
    > >> > I am prompted with a file open dialog box. When I select the file to be
    > >> > opened and click ok, the dialog box goes away and my file is not
    > >> > opened. Is
    > >> > there more code that I have to add to the macro?

    >
    >
    >


  7. #7
    Tom Ogilvy
    Guest

    Re: Application.GetOpenFileName

    If the file you select is a textfile, you will get the text import wizard.
    --
    Regards,
    Tom Ogilvy


    "Chris" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks that worked, but I have one more issue. I would like Excel to
    > prompt
    > me with the text import wizzard if need be because my files need to be
    > delimited with certain characters or my macro will not work. So after the
    > user selects the file to be opened, a text import wizard box pops up
    > asking
    > about delimited or fixed width options. Is there a way to do this?
    >
    > "Tom Ogilvy" wrote:
    >
    >> Dim fname as String, bk as Workbook
    >> fname = Application.GetOpenfilename()
    >> if fname <> "False" then
    >> set bk = Workbooks.Open(fname)
    >> else
    >> exit sub
    >> end if
    >> msgbox bk.name & " has been opened"
    >>
    >> --
    >> Regards,
    >> Tom Ogilvy
    >>
    >>
    >> "Chris" wrote:
    >>
    >> > When I type this line into the beginning of my macro and then run the
    >> > macro,
    >> > I am prompted with a file open dialog box. When I select the file to be
    >> > opened and click ok, the dialog box goes away and my file is not
    >> > opened. Is
    >> > there more code that I have to add to the macro?




  8. #8
    Tom Ogilvy
    Guest

    Re: Application.GetOpenFileName

    Sorry, I was thinking of the Builtin Dialog - disregard.

    --
    Regards,
    Tom Ogilvy

    "Tom Ogilvy" <[email protected]> wrote in message
    news:uiq%[email protected]...
    > If the file you select is a textfile, you will get the text import wizard.
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Chris" <[email protected]> wrote in message
    > news:[email protected]...
    >> Thanks that worked, but I have one more issue. I would like Excel to
    >> prompt
    >> me with the text import wizzard if need be because my files need to be
    >> delimited with certain characters or my macro will not work. So after
    >> the
    >> user selects the file to be opened, a text import wizard box pops up
    >> asking
    >> about delimited or fixed width options. Is there a way to do this?
    >>
    >> "Tom Ogilvy" wrote:
    >>
    >>> Dim fname as String, bk as Workbook
    >>> fname = Application.GetOpenfilename()
    >>> if fname <> "False" then
    >>> set bk = Workbooks.Open(fname)
    >>> else
    >>> exit sub
    >>> end if
    >>> msgbox bk.name & " has been opened"
    >>>
    >>> --
    >>> Regards,
    >>> Tom Ogilvy
    >>>
    >>>
    >>> "Chris" wrote:
    >>>
    >>> > When I type this line into the beginning of my macro and then run the
    >>> > macro,
    >>> > I am prompted with a file open dialog box. When I select the file to
    >>> > be
    >>> > opened and click ok, the dialog box goes away and my file is not
    >>> > opened. Is
    >>> > there more code that I have to add to the macro?

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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