+ Reply to Thread
Results 1 to 8 of 8

Referencing active workbook file name in code automatically.

  1. #1
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Referencing active workbook file name in code automatically.

    Good morning. I'm not sure my title captures what I'm shooting for so if I can give this thread a more accurate title please chime in.

    The following line of code works great for automatically copying information from one workbook into a brand new workbook. It works perfectly as long as I manually enter the correct file name+extension of the workbook I'm copying from.

    Please Login or Register  to view this content.
    I would like to use this line of code in a form that my users will be opening, saving, closing, opening, re-saving as a different file name, closing......you get the picture. My users will not be able to go into the code and change the file name every time the file name changes. Is there a way to write the code so it will find the file name automatically?

    Please Login or Register  to view this content.
    I've attached a mock workbook for review. Thanks.

    Matthew
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Referencing active workbook file name in code automatically.

    Why not?

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Referencing active workbook file name in code automatically.

    John,

    That works brilliantly! Thanks. BTW, I've tried (and failed up to this point) to automatically "deselect" the range that's copied in the originating Sheet and I can't seem to get the code correct. Thoughts?

    Thanks again.

    Matthew
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Referencing active workbook file name in code automatically.

    What do you mean by deselect? What is you ultimate goal? Would selection.copy be an option?

  5. #5
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Referencing active workbook file name in code automatically.

    Quote Originally Posted by JOHN H. DAVIS View Post
    What do you mean by deselect?
    When I return to the workbook, where my data was just copied from, the range is still bordered by the "blinking" border. I can hit Esc and it goes away but I was hoping to add a line of code to do this automatically.

    I added a line of code and it seems to be working...I need to test it more to make sure it's solid.

    Please Login or Register  to view this content.
    Just for curiosity's sake, what would you have suggested to address the issue? Thanks.

    Matthew

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Referencing active workbook file name in code automatically.

    No you hit it on the nail. I just wasn't sure of what you meant by deselect.

  7. #7
    Forum Contributor
    Join Date
    02-22-2014
    Location
    Winthrop, ME
    MS-Off Ver
    Excel 2010
    Posts
    420

    Re: Referencing active workbook file name in code automatically.

    John,

    Thank.

    Matthew

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Referencing active workbook file name in code automatically.

    You're welcome. Glad to help out.

+ 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] Code to detect previous active workbook instead of current active workbook
    By kosherboy in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-25-2014, 01:58 AM
  2. [SOLVED] Trouble copying data from closed workbook into active workbook, referencing help
    By lepperga in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-20-2013, 01:48 PM
  3. Automatically extract data from another file in the same folder as the active workbook
    By msexceljones in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-30-2013, 12:51 AM
  4. Replies: 5
    Last Post: 03-21-2013, 07:34 AM
  5. [SOLVED] Edit code to close all workbooks except active workbook and other specific workbook
    By rocksan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-04-2012, 09:29 PM

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