+ Reply to Thread
Results 1 to 18 of 18

Automatically Update the Filename in VBA

  1. #1
    Registered User
    Join Date
    05-08-2017
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    23

    Automatically Update the Filename in VBA

    Many Many Thanks in advance.

    Dear All,
    I am running a series of commands in one macro, such as setting the filter criteria in File#1 (here LB – 201.xlsm) and based on the set criteria, filtering on File#2 and copying and pasting the filtered data back into File#1. Macro is running perfectly.
    The problem starts when I am changing the file name of File#1 ("LB - 201" to say "LB - 202" or any other name).
    I want to keep the reference "LB - 201.xlsm" as dynamic.

    Here is the macro.

    Please Login or Register  to view this content.
    Last edited by mushtaq.ams; 05-08-2017 at 05:55 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,858

    Re: Automatically Update the Filename in VBA

    What file contains this VBA?

    What do you mean by "dynamic"? How can VBA automatically determine what file name you have in mind? Do you want to put the filename in a cell? Can the filename be determined automatically by date?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Automatically Update the Filename in VBA

    I think if you are on the activeworkbook at the begining of the code creating a variable eg
    Please Login or Register  to view this content.
    will suffice then you reference this in the rest of the code

    Dav

  4. #4
    Registered User
    Join Date
    05-08-2017
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    23

    Re: Automatically Update the Filename in VBA

    Dear davsth

    Thanks for your response.
    But this didn't worked.

    If you allow, then wish to send you both the excel files. Hope that will clarify my doubt in a proper way.

    Thanks again.

    Cheers !!!

  5. #5
    Registered User
    Join Date
    05-08-2017
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    23

    Re: Automatically Update the Filename in VBA

    Dear String,

    Thanks for your time in reviewing and posting a reply.

    I think you got it correctly.
    I want the vba in File#01 to determine its name automatically in the code.
    Filename of File#02 remains standard (in my case).

  6. #6
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Automatically Update the Filename in VBA

    what didn't work?
    if for example
    Please Login or Register  to view this content.
    is determined at the top of the vba code. Assuming the code is in LB - 201.xlsm and not the other file

    as it is what is returned by curwbname = ActiveWorkbook.Name

    then you modify
    Please Login or Register  to view this content.
    to something like
    Please Login or Register  to view this content.
    and so on for the rest

    what is it falling down on?

    Dav
    Last edited by davsth; 05-09-2017 at 04:41 AM.

  7. #7
    Registered User
    Join Date
    05-08-2017
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    23

    Re: Automatically Update the Filename in VBA

    Dear Dav,

    Thanks for the reply.
    I will try with this new code, and will update here.

    Thank again.

  8. #8
    Registered User
    Join Date
    05-08-2017
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    23

    Re: Automatically Update the Filename in VBA

    Dear Dav,

    it worked fine upper half..... Thanks a ton for this.

    It struck in lower half of code, where I am coming back and pasting the data.

    The original was

    Please Login or Register  to view this content.
    I modified to

    Please Login or Register  to view this content.
    This is the debugged line.

  9. #9
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Automatically Update the Filename in VBA

    Please Login or Register  to view this content.
    Does that work

  10. #10
    Registered User
    Join Date
    05-08-2017
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    23

    Re: Automatically Update the Filename in VBA

    Dear Dav,

    Lots of respect.
    Thanks a lot.


    It really worked.

    Many Many Thanks.

  11. #11
    Registered User
    Join Date
    05-08-2017
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    23

    Re: Automatically Update the Filename in VBA

    Dear Dav,

    Do we have anything similar for current work sheet.

    What is mean is
    For current workbook we define "curwbname = ActiveWorkbook.Name"

    For current worksheet, can we define like this "curwksheet = ActiveWorksheet.Name"

  12. #12
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Automatically Update the Filename in VBA

    the name can be anything i just made up curwbname as it made vague sense, but I could have called it mushtaq or dav or..... its just a name
    amazingly the current worksheet is ActiveSheet.Name, you were close!

    so something like curwsname= ActiveSheet.Name

  13. #13
    Registered User
    Join Date
    05-08-2017
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    23

    Re: Automatically Update the Filename in VBA

    Dear Dav,

    Thanks a lot and
    again Many Many Thanks.

    Your guidance was really helpful.

    Wish you loads of success.
    Cheers !!!

  14. #14
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2404
    Posts
    24,858

    Re: Automatically Update the Filename in VBA

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

    If a member helped you solve your problem, consider adding to their reputation by clicking on the star icon below their name.

  15. #15
    Registered User
    Join Date
    05-08-2017
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    23

    Re: Automatically Update the Filename in VBA

    Dear 6String,

    Thanks for the info. I will do that.

  16. #16
    Registered User
    Join Date
    05-08-2017
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    23

    Re: Automatically Update the Filename in VBA

    Dear Dav,

    Just a quick question.
    If i define a name of work book in a cell (say in cell H2 as "Beam Design Summary.xlsm" or anything, can we call this reference in VBA )
    I hope i am clear in my question.

  17. #17
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Automatically Update the Filename in VBA

    Sorry the internet has been down at work, with all the IT issues since friday, only just back up

    yes mushtaqname=range("H2").value
    or mushtaqname=sheets("Mushtaqsheet").("H2").value

    obviously you can change mushtaqname an mushtaqsheet to whatever you see fit

  18. #18
    Registered User
    Join Date
    05-08-2017
    Location
    Dubai
    MS-Off Ver
    2013
    Posts
    23

    Re: Automatically Update the Filename in VBA

    Dear Dav,

    Thanks for the reply, and I wish and hope the services at your end and around the world restores quickly.

    Thanks for help with above syntax.
    But unfortunately it didnt worked.

    I posted a new thread for the same and below is the link for that .
    https://www.excelforum.com/excel-pro...ml#post4657487

+ 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. Filename does not update automatically
    By L.LEE in forum Excel General
    Replies: 2
    Last Post: 06-24-2015, 11:39 AM
  2. Automatically update only with numbers(ifnumber-update and go to next cell)
    By moldo89 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-18-2013, 11:10 AM
  3. Automatically update only with numbers(ifnumber-update and go to next cell)
    By moldo89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-18-2013, 03:06 AM
  4. Replies: 4
    Last Post: 10-18-2013, 02:52 AM
  5. [SOLVED] Find if filename exists and update variable within the filename structure
    By Lungfish in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-18-2013, 02:42 AM
  6. Automatically update existing data using a Update command button
    By 9999335 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-23-2012, 09:46 PM
  7. [SOLVED] Adding Footer with Filename Path (with UPDATE)
    By T86157 in forum Word Formatting & General
    Replies: 2
    Last Post: 05-31-2012, 04:53 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