Closed Thread
Results 1 to 13 of 13

How to stop Excel from changing a file path in a formula

  1. #1
    Registered User
    Join Date
    10-22-2017
    Location
    ENGLAND
    MS-Off Ver
    2016
    Posts
    35

    How to stop Excel from changing a file path in a formula

    I'm entering a formula into a cell that refers to a file path of another workbook e.g. ='C:\Documents\[Costs for Week 1.xlsx]sheet1'!$A$1

    and this formula returns a value from the cell A1 in that file - works great even if the file is closed.

    However the person who uses the file will soon create the file "costs for week 2.xlsx" by saving the week 1 file using "save as".
    Or alternatively if someone changes the file name of week 1.xlsx name to week 2.xlsx.

    Now when this happens, excel automatically changes the file path in my formula to ='C:\Documents\[Costs for Week 2.xlsx]sheet1'!$A$1

    But I want the formula to stay as I typed it i.e. ='C:\Documents\[Costs for Week 1.xlsx]sheet1'!$A$1


    How do I enter a formula in excel so that excel cannot change it when it wants to i.e. I want an absolute file path in the formula.

    I want to have the power over the formula and keep it as I typed it in !!! Excel 2016

    Please help :-)
    Last edited by david killoran; 03-09-2019 at 01:22 PM.

  2. #2
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: How to stop Excel from changing a file path in a formula

    save as a template, not Week##

  3. #3
    Registered User
    Join Date
    10-22-2017
    Location
    ENGLAND
    MS-Off Ver
    2016
    Posts
    35

    Re: How to stop Excel from changing a file path in a formula

    Dear tim201110,
    Thanks for the reply and the suggestion, however I am unable to influence how the files are saved or copied.
    There are a few work arounds I can use, but I really would like a way to stop excel from changing my formulas.
    Is there a way to make a file path in a formula absolute, perhaps using &?
    My laptop is about to end up in the fishtank ;-)

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,728

    Re: How to stop Excel from changing a file path in a formula

    Maybe try this (untested):

    =INDIRECT("'C:\Documents\[Costs for Week 1.xlsx]sheet1'!"&$A$1)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    10-22-2017
    Location
    ENGLAND
    MS-Off Ver
    2016
    Posts
    35

    Re: How to stop Excel from changing a file path in a formula

    Dear Ali,
    Thanks for the suggestion, which would be perfect except that using indirect will return an error if the source files are closed, and I am not able to open them as they are too large. There is no logical reason why using indirect in the destination workbook won't allow linking to source closed files - but for some reason excel wont allow this !
    Don't worry, I am sure that my laptop will make a good ornament for my fish to swim around, and at least the snails will keep the screen clean.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,728

    Re: How to stop Excel from changing a file path in a formula

    OK, so define the static URL in a cell in the open workbook and then use INDIRECT with that cell.

    I don't think you should blame your laptop. It can only do what you tell it to.

    PS Have you tried adding an error trap?

    =IFERROR(your_formula,"")
    Last edited by AliGW; 03-10-2019 at 04:12 AM.

  7. #7
    Registered User
    Join Date
    10-22-2017
    Location
    ENGLAND
    MS-Off Ver
    2016
    Posts
    35
    Hi Ali,
    Thanks this works with Indirect, but only when the source file is open. Apparently this is an issue with indirect that other bloggers have also seen. It doesnt make sence. Otherwise this would be the perfect solution. It seems that whatever I try, excel has some little quirk that gets in the way. I now have the ifferror in my formula that says "grrr" when the error occurs. Have you seen this issue with indirect where the source file has to be open?

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,728

    Re: How to stop Excel from changing a file path in a formula

    Yes, it's a known issue that some functions won't work unless the workbook referenced is open.

    I don't understand exactly what the context is of what you are trying to do, but it might be achievable using PowerQuery.

    Two possibly useful links:

    https://exceloffthegrid.com/getting-...xcel-workbook/

    https://www.youtube.com/watch?v=-0cDSt0Io40

  9. #9
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: How to stop Excel from changing a file path in a formula

    Only cell references can be made absolute. Worksheet and Workbook references are linked to the object, not the name, this means when you change the name the formula will follow.
    Think how many people create formulas that cross reference other workbooks / worksheets and how easily people could break those formulas by simply changing the name of one of them. The problem you are encountering is annoying but deliberate, the software engineers that created excel would have thought of things like this and catered for what is undoubtedly the more common of the 2 situations.

    The sensible fix for this is to educate users and change the way that the file is saved / created as Tim has already suggested.

    Do you want to keep the formulas the same, or just keep the values?

    I ask this because in the situation that you describe in post #1

    Quote Originally Posted by david killoran View Post
    Or alternatively if someone changes the file name of week 1.xlsx name to week 2.xlsx.

    Now when this happens, excel automatically changes the file path in my formula to ='C:\Documents\[Costs for Week 2.xlsx]sheet1'!$A$1

    But I want the formula to stay as I typed it i.e. ='C:\Documents\[Costs for Week 1.xlsx]sheet1'!$A$1
    If the user changed the name from week 1 to week 2 then the original week 1 file would no longer exist, so there would be nothing for the formulas to look at if they were still looking for week 1.

    Copy - PasteSpecial values would be a simple fix in this case.

  10. #10
    Registered User
    Join Date
    10-22-2017
    Location
    ENGLAND
    MS-Off Ver
    2016
    Posts
    35

    Re: How to stop Excel from changing a file path in a formula

    Jason/Ali thank you for your advice,
    Jason in answer to your question, my worksheet gets values for all of the weeks, and the weeks where the file does not exist just comes up with a blank due to the iff error part off the formula. The idea is that when a new week e.g. week 2.xlsx is created, the spreadsheet will then automatically get the values. (but if week 2 is created by "saving as" week 1, then the formula will change and I will get week 1's values because the formula will change. If you think that the there is no way to make a file path absolute, then I will try and find a workaround. I have just created a vba code that will keep re-inserting all of the formulas - messy but I can't think of another way.. grrrrr.... Solutions that use "Indirect" and "names", don't work on closed workbooks. I cant' help but feel that the quantum world of Microsoft excel is conspiring against me...........

  11. #11
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: How to stop Excel from changing a file path in a formula

    Find and Replace (ctrl h) can be used to change part of a formula.

    Not knowing your sheet layout, this is only a theoretical method that I would use for the task.

    Assuming that you have the formula, ='C:\Documents\[Costs for Week 1.xlsx]sheet1'!$A$1 in A1, with the correct week '"Week 1' in B1, either apply a helper column or conditional formatting (preferred) using the formula =ISERROR(SEARCH($B1,FORMULATEXT($A1))) to highlight cells where the formula doesn't match the correct week number, then select those cells and replace Week 2 with Week 1 using ctrl h.

  12. #12
    Registered User
    Join Date
    12-13-2022
    Location
    USA
    MS-Off Ver
    365 for enterprise
    Posts
    3

    Re: How to stop Excel from changing a file path in a formula

    Did you ever figure out how to make Excel stop changing the file path? I am having the same issue when I "save as" to a different file name. I need to keep the original file path and also need to rename the file. Thanks.

    RJ

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,728

    Re: How to stop Excel from changing a file path in a formula

    Administrative Note:

    This is an old thread.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 08-18-2017, 02:55 PM
  2. Excel Changing Formula Format - Please help me STOP it!
    By mjhopler in forum Excel General
    Replies: 10
    Last Post: 04-03-2014, 08:42 AM
  3. [SOLVED] Stop Excel from changing numbers to dates in CSV file
    By Curt L. in forum Excel General
    Replies: 3
    Last Post: 11-04-2013, 12:26 PM
  4. Vlookup file path keeps changing - XL2007
    By plunsford0221 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-08-2013, 05:37 PM
  5. Replies: 3
    Last Post: 11-27-2012, 06:01 AM
  6. VBA Changing a fixed file path with open file dialog box
    By Dan27 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2011, 08:54 AM
  7. Changing external path and file name
    By chemaster in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-06-2005, 10:27 AM

Tags for this Thread

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