+ Reply to Thread
Results 1 to 17 of 17

How to open named Excel file & Worksheet

  1. #1
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    How to open named Excel file & Worksheet

    Hi VBA Experts…
    I have the following code that opens a specific file. However the file Path & Name is hard coded.
    Please could you help me amend such that –
    a. User defines Path in cell “E14” of active worksheet called “RunCode_TEST”
    b. User defines File name in “E16” of the same worksheet
    c. User defines specific worksheet in cell “E18” of the same worksheet.

    What I want is the code to look thru the Path (E14), opens Excel - namedfile (E16) and selects cell "A1" on the specified worksheet (E18).

    The code I have is -

    Please Login or Register  to view this content.
    Thanking you in advance
    Dhiresh

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to open named Excel file & Worksheet

    Please Login or Register  to view this content.
    essentially,the path will need to end in "/" and the filename will need the extension.

  3. #3
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: How to open named Excel file & Worksheet

    Hi yudlugar,
    Thx for your prompt reply.

    I have very little knowledge of VBa and by replacing code with the above line you suggested is not working. Perhaps you could advise on how to amend my code.

    rgds
    Dhiresh

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to open named Excel file & Worksheet

    replace:
    Please Login or Register  to view this content.
    with the code I gave you, if that doesn't work try running this macro:
    Please Login or Register  to view this content.
    and see if it is giving you the path you expect...

  5. #5
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: How to open named Excel file & Worksheet

    Hi yudlugar,
    Yes. it is not working.
    many Thanks

    Dhiresh

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to open named Excel file & Worksheet

    What is in cells E14 and E16

  7. #7
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: How to open named Excel file & Worksheet

    I have recheck & have managed to open the file but the actual worksheet is not selected. this is what I meant. sorry for being to vague.

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to open named Excel file & Worksheet

    Sorry, it should be
    sheetname = Range("E18")
    Workbooks.Open Filename:=Range("E14") & Range("E16")
    Sheets(sheetname).Range("A1").select

  9. #9
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: How to open named Excel file & Worksheet

    I have tried the revised code and the file is opening as it should but the code is still not opening the named tab and Cell A1. Any advise!!!!

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to open named Excel file & Worksheet

    Please can you upload both workbooks (remove any sensitive data) with the code you are using and I'll take a look.

  11. #11
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: How to open named Excel file & Worksheet

    Hi.
    Attaching 2 files as requested.

    Rgds
    D
    Attached Files Attached Files

  12. #12
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to open named Excel file & Worksheet

    You were close, you defined the sheetname as a worksheet and I used it as a string, you need to use:
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: How to open named Excel file & Worksheet

    HI.

    Thx for update and I will try your code tomorrow morning & will update the thread appropraitely

    Rgds
    D

  14. #14
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: How to open named Excel file & Worksheet

    Hi,
    I have copied your code on actual file and tested on a number of files and the file opens as expected but I can only see the first worksheet in all cases. Code to open the specified worksheet is not working.

    Help!!!

    D

  15. #15
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to open named Excel file & Worksheet

    One more go:
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: How to open named Excel file & Worksheet

    Excellent. it is now working.
    Many thanks

    Rgds
    Dhiresh

  17. #17
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    Re: How to open named Excel file & Worksheet

    Excellent. It is now working.
    Many Thanks.

    Rgds
    D

+ 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] open variably named file, copy/paste data into consolidation file, open next file in list
    By sllawrence1968 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:49 PM
  2. [SOLVED] VBA - Open Excel Files with file path from Named Ranges
    By bbg22 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-06-2012, 11:41 PM
  3. Open Variably-named File
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-24-2010, 12:28 PM
  4. Open New Instance Of Excel With Named File
    By Launchnet in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-09-2007, 10:25 PM
  5. How do I open a file from a named cell?
    By Cumberland in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-23-2006, 04:15 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