Filename

%3CLINGO-SUB%20id%3D%22lingo-sub-1758583%22%20slang%3D%22en-US%22%3EFilename%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1758583%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%C2%B4m%20using%20the%20Cell(filename)%20function%2C%20and%20this%20is%20working.%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20I%20have%202%20or%20more%20Excel%20sheets%20open%2C%20with%20the%20same%20formula%20but%20different%20file%20names.%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20when%20I%20work%20in%20one%20file%2C%20it%20changes%20the%20name%20in%20all%20other%20Cell(filename)%20functions%2C%20to%20the%20one%20I'm%20currently%20working%20in.%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20a%20way%20to%20fix%20this%3F%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1758583%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1758594%22%20slang%3D%22en-US%22%3ERe%3A%20Filename%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1758594%22%20slang%3D%22en-US%22%3ECell(%22Filename%22%2CCellRef)%20returns%20the%20current%20Workbook%20name%2C%2C%2C%20please%20share%20the%20file%20you%20are%20working%20with%2C%20will%20help%20us%20to%20examine.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1762856%22%20slang%3D%22en-US%22%3ERe%3A%20Filename%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1762856%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F93699%22%20target%3D%22_blank%22%3E%40Rajesh-S%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20this%20but%20this%20does%20not%20work.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1762867%22%20slang%3D%22en-US%22%3ERe%3A%20Filename%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1762867%22%20slang%3D%22en-US%22%3EBetter%20upload%20the%20workbook%20and%20mark%20the%20cell%20in%20which%20you%20have%20applied%20the%20formula%20and%20let%20me%20examine%2C%2C%2C%20also%20if%20possible%20show%20me%20the%20expected%20output.%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Hello 

 

I´m using the Cell(filename) function, and this is working. 

But I have 2 or more Excel sheets open, with the same formula but different file names. 

But when I work in one file, it changes the name in all other Cell(filename) functions, to the one I'm currently working in. 

Is there a way to fix this? 

8 Replies
Highlighted
Cell("Filename",CellRef) returns the current Workbook name,,, please share the file you are working with, will help us to examine.
Highlighted

@Rajesh-S 

I tried this but this does not work. 

Highlighted
Better upload the workbook and mark the cell in which you have applied the formula and let me examine,,, also if possible show me the expected output.
Highlighted

@Rajesh-S 

There is no problem when I rename and safe this file. 

But when I open 2 or more Excel files at the sam time, they all get the same name, instead of getting the name og the sheet they are used in. 

 

Highlighted

@MMourits 

 

I got the issue ,, what you have to do ,,if you want to DUPLICATE it ,,, use SAVE as and assign another name,, rather then RENAME it. 

 

And even you have RENAME it then also it works ,,,, what I have noticed when open the file cell has ### is problem with width,,, or you just select cell E1 press F2 and finish with Ctrl+Shift+Enter.

 

  • Check I've loaded files are 3,,, 1 is yours 2nd is after SAVED as 3 is RENAME ,, all are working.

 

  • In case if U open all 3 together and finds the issue ,,, just select cell E1 press F2 and finish with Ctrl+Shift+Enter.

Let me find out a smart solution the I'll return soon to U.

  •  
Highlighted

@Rajesh-S 

 

Hello 

It is still doing the same, I opened all 3 files and safeed them.
But they stille show the same name, in the work sheet, but not the file name of the sheet the formula i used in. 

 
 

image.png

Highlighted

 

@Rajesh-S 

Found it:) 

by adding A1 in the referene it refferes to the current sheet and not the aktive one.  

 

Highlighted

@MMourits 

 

This is the permanent solution. What you have to do is, use VBA macro for Workbook_Activate  event.

 

Private Sub Workbook_Activate()

Range("E1").FormulaArray = "= MID(CELL(""filename""),SEARCH(""["",CELL(""filename""))+1,SEARCH(""]"",CELL(""filename""))-SEARCH(""["",CELL(""filename""))-6)"

End Sub

 

How it works:

  1. Open the 1st file, and to open the VB editor, press ALT + F11 .
  2. As soon you get the editor, find This Workbook Icon on left side in Project Explorer Windows.
  3. Click it.
  4. Copy & Paste above shown code.
  5. Press  ALT+Q to return to the Sheet.
  6. Now save the file as, MACRO ENABLED *.xlsm.
  7. Close the file.

Repeat step 1 to 7 with other file.

 

  • Now if you open all files together, and transfer control from one file to other, Excel will apply the Workbook_Activate event ,, and apply the array formula in cell E1 ,, and in this way STOP using the old file name.

Check the attached file for the code.