+ Reply to Thread
Results 1 to 9 of 9

Application.GetOpenFilename

  1. #1
    Registered User
    Join Date
    06-02-2010
    Location
    Hometown, Texas
    MS-Off Ver
    Excel 2003
    Posts
    23

    Application.GetOpenFilename

    I am using one Master Workbook to create an Open File dialogue box in which the user selects a specific type of Log File to open; at this point the Master scans and copies rows to paste into another sheet which resides in the Master. My problem is that I cannot activate the newly opened file so that the Macro selects the data.

    Please Login or Register  to view this content.
    As you can see, if the code attempts to select the Range, it is doing so on the Master book, giving me errors. The range selection is supposed to be on the newly opened sheet. I am not sure what to use to activate the window of the new file, and I cannot use a static name since it depends on what file the user selects to open.
    Last edited by Screamtruth; 06-06-2010 at 02:52 PM.
    Of all tyrannies, a tyranny exercised "for the good of its victims" may be the most oppressive.
    --C. S. Lewis

  2. #2
    Registered User
    Join Date
    06-06-2010
    Location
    gloucester
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Application.GetOpenFilename

    I found that the code below helped me. if u set this at the start of the macro:

    Please Login or Register  to view this content.
    then once the new workbook has been opened:

    Please Login or Register  to view this content.
    once you have set a defined name you should then be able to reference them..

    hope this helps!!
    Last edited by royUK; 06-06-2010 at 02:12 PM. Reason: add code tags

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Application.GetOpenFilename

    Stubarso, please take a few minutes to read the forum rules, and then edit your post to add CODE tags.

    Thanks.

    Screamtruth, if the workbook opens, it becomes the active workbook. Your code should be modified to exit if the user cancels:
    Please Login or Register  to view this content.
    Last edited by shg; 06-06-2010 at 01:15 PM.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Application.GetOpenFilename

    Open returns the workbook in question.
    This avoids selecting

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    06-02-2010
    Location
    Hometown, Texas
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Application.GetOpenFilename

    Thanks shg,

    I had edit the code to exit the sub if the user cancels,.

    The only issue I still have is an error returned when the sub attempts to select the range; it tells me the range selection fails. I am not sure what is causing this, which is why I suspected that the window was not activated since the code is running from a button click on the Master workbook.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Application.GetOpenFilename

    Try this. Confirm the selection when the code reaches the Stop, or set a breakpoint and single-step through the code.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-02-2010
    Location
    Hometown, Texas
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Application.GetOpenFilename

    Very nice, and very effective.

    How would I close the newly opened file upon completion of the paste?
    Last edited by shg; 06-06-2010 at 02:44 PM. Reason: deleted spurious quote

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Application.GetOpenFilename

    Please Login or Register  to view this content.
    Please don't quote whole posts; it's just clutter.

  9. #9
    Registered User
    Join Date
    06-02-2010
    Location
    Hometown, Texas
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Application.GetOpenFilename

    Sorry for the multi-quote posts.

    Thank you for your time.

+ 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