+ Reply to Thread
Results 1 to 4 of 4

Referencing the File Name dynamically within the VBA code

  1. #1
    Registered User
    Join Date
    02-19-2013
    Location
    Norwich, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Referencing the File Name dynamically within the VBA code

    Hi,

    I'm fairly new to this, but I've made a macro which produces email bonus statements for people at work.

    It copies data into a template, emails it to the relevant person, saves a copy and then loops to the next person etc.

    However when I 'flip back' from the saved/closed workbook to the main workbook I reference it's name. I was hoping to reference a dynamic filename so if I called the file "Bonus -Week 1", and next week "Bonus -Week 2" etc, I wouldn't have to change this in the VBA. Can anyone point me in the correct direction?

    Cheers

    Here's the bottom part of my code - hopefully it's worked and highlighted the line in question! Cheers
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 05-14-2015 at 12:38 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Referencing the File Name dynamically within the VBA code

    I would just use:

    Please Login or Register  to view this content.
    Note that activating the workbook and selecting the sheet is usually unnecessary. It mainly has a visual effect. You can just use a with block to perform actions on that workbook/sheet without having to activate it.
    1. Include a sample workbook with an example of the result you want
    2. Use [CODE] and [FORMULA] wrappers for your VBA code or excel formulas
    3. If your question has been answered, mark the thread as SOLVED and click on the "Add Rep" star to thank whoever helped you.

  3. #3
    Registered User
    Join Date
    02-19-2013
    Location
    Norwich, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Referencing the File Name dynamically within the VBA code

    Thanks for your help, this worked a charm. Sorry I thought I'd posted my thanks yesterday!

    Learned something new about with blocks so appreciate the time taken to help me out!

  4. #4
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Referencing the File Name dynamically within the VBA code

    You're welcome. Glad I could help!

+ 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] Referencing active workbook file name in code automatically.
    By moosetales in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-24-2014, 10:18 AM
  2. Dynamically referencing file in concatenate
    By coryg in forum Excel General
    Replies: 2
    Last Post: 10-05-2010, 02:12 PM
  3. Referencing Tabs Dynamically
    By sclarence in forum Excel General
    Replies: 2
    Last Post: 08-24-2009, 05:10 PM
  4. [SOLVED] dynamically referencing to another worksheet
    By D23 in forum Excel General
    Replies: 2
    Last Post: 06-23-2006, 11:10 AM
  5. [SOLVED] Hlep with code referencing an addin file.
    By KimberlyC in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-17-2005, 06:06 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