Link part of file name to Excel cell

%3CLINGO-SUB%20id%3D%22lingo-sub-2343775%22%20slang%3D%22en-US%22%3ELink%20part%20of%20file%20name%20to%20Excel%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2343775%22%20slang%3D%22en-US%22%3E%3CP%3EI%20would%20like%20to%20link%20part%20of%20the%20filename%20to%20part%20of%20a%20cell.%20The%20name%20of%20the%20Excel%20file%20is%20Excel%20Mar%20Sample.%20The%20string%20in%20an%20Excel%20cell%20is%20%22MTD%20Mar%20CY2021%22.%20I%20would%20like%20to%20like%20the%20Mar%20in%20the%20filename%20to%20the%20Cell%20so%20that%20when%20I%20name%20the%20file%20in%20the%20future%20Excel%20Apr%20Sample%2C%20the%20string%20in%20the%20Excel%20cell%20is%20MTD%20Apr%20CY2021.%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2343775%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2344053%22%20slang%3D%22en-US%22%3ERe%3A%20Link%20part%20of%20file%20name%20to%20Excel%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2344053%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F928871%22%20target%3D%22_blank%22%3E%40Chan_Tze_Leong%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECreate%20a%20defined%20name%20FileName%20that%20refers%20to%20%3DGET.DOCUMENT(88)%3C%2FP%3E%0A%3CP%3EYou%20can%20then%20use%3C%2FP%3E%0A%3CP%3E%3D%22MTD%20%22%26amp%3BMID(FileName%2CFIND(%22%20%22%2CFileName)%2B1%2CFIND(%22%20%22%2CFileName%2CFIND(%22%20%22%2CFileName)%2B1)-FIND(%22%20%22%2CFileName)-1)%26amp%3B%22%20CY2021%22%3C%2FP%3E%0A%3CP%3ESee%20the%20attached%20version%20(now%20a%20macro-enabled%20workbook).%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2347237%22%20slang%3D%22en-US%22%3ERe%3A%20Link%20part%20of%20file%20name%20to%20Excel%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2347237%22%20slang%3D%22en-US%22%3EDear%20Hans%20%2C%3CBR%20%2F%3E%3CBR%20%2F%3Eif%20the%20FileName%20is%20KPI%20CY2021%20XXX_Apr.xlsm%20and%20XXX%20will%20change%20in%20length%2C%20how%20does%20the%20formula%20change%20to%20extract%20Apr%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2360180%22%20slang%3D%22en-US%22%3ERe%3A%20Link%20part%20of%20file%20name%20to%20Excel%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2360180%22%20slang%3D%22en-US%22%3EDear%20Hans%2C%20When%20I%20save%20the%20filename%20say%20to%20Apr%2C%20the%20output%20still%20shows%20Mar.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2360282%22%20slang%3D%22en-US%22%3ERe%3A%20Link%20part%20of%20file%20name%20to%20Excel%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2360282%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F928871%22%20target%3D%22_blank%22%3E%40Chan_Tze_Leong%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUnfortunately%2C%20that%20formula%20isn't%20updated%20automatically%2C%20you%20have%20to%20do%20that%20manually.%3C%2FP%3E%0A%3CP%3EHere%20is%20another%20version.%20It%20uses%20a%20helper%20cell.%3C%2FP%3E%0A%3CP%3EThis%20time%20it%20is%20an%20ordinary%20workbook%20(not%20macro-enabled).%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2362718%22%20slang%3D%22en-US%22%3ERe%3A%20Link%20part%20of%20file%20name%20to%20Excel%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2362718%22%20slang%3D%22en-US%22%3EThis%20will%20basically%20reside%20is%20Sharepoint%2FMS%20Teams.%20Can%20it%20still%20run%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2362721%22%20slang%3D%22en-US%22%3ERe%3A%20Link%20part%20of%20file%20name%20to%20Excel%20cell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2362721%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F127945%22%20target%3D%22_blank%22%3E%40Hans%20Vogelaar%3C%2FA%3E%26nbsp%3BEven%20though%20I%20saved%20as%20Apr%2C%20the%20link%20could%20not%20be%20updated.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

I would like to link part of the filename to part of a cell. The name of the Excel file is Excel Mar Sample. The string in an Excel cell is "MTD Mar CY2021". I would like to like the Mar in the filename to the Cell so that when I name the file in the future Excel Apr Sample, the string in the Excel cell is MTD Apr CY2021.      

8 Replies

@Chan_Tze_Leong 

Create a defined name FileName that refers to =GET.DOCUMENT(88)

You can then use

="MTD "&MID(FileName,FIND(" ",FileName)+1,FIND(" ",FileName,FIND(" ",FileName)+1)-FIND(" ",FileName)-1)&" CY2021"

See the attached version (now a macro-enabled workbook).

Dear Hans, When I save the filename say to Apr, the output still shows Mar.

@Chan_Tze_Leong 

Unfortunately, that formula isn't updated automatically, you have to do that manually.

Here is another version. It uses a helper cell.

This time it is an ordinary workbook (not macro-enabled).

This will basically reside is Sharepoint/MS Teams. Can it still run?

@Hans Vogelaar Even though I saved as Apr, the link could not be updated.

@Chan_Tze_Leong 

I cannot explain that, sorry.

And I don't know anything about SharePoint, so I cannot help you with that.

@Chan_Tze_Leong 

Excel in Teams is actually Excel for web. It doesn't support VBA and GET.DOCUMENT function, as well as cell("filename").  Moreover, link on the current file, if check it in File->Info, starts from "https://...".

So far I don't know the way to receive the filename in Excel Online, if maybe with Office Scripts.

Excel recalculates prior to saving the workbook, not immediately after (if it did, and something changed, then it would prompt the user to save it again before closing because it changed since the last save operation and could create a confusing cycle for the user). But, it will update when next excel calculates (if you save the workbook, then enter a value in any cell you will see it update). Also, it should update when the file is closed/reopened.