I use the following formula to extract the filename of a workbook to build a hyperlink with it:
=MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,FIND("]", CELL("filename",A1))-FIND("[",CELL("filename",A1))-1)
However I personally use a Dutch version of excel, therefore I translated the "filename" manually to suit my locale. Now I have a international contact that wants to use this in a workbook as well, but in a number of different locale's.
Is there a way to extract "filename" using a formula, as to get the appropriate word for any given locale?
Supposing the string "filename" is in cell A1 then =CELL($A$1,A1) should work.
In my German Excel then I can change A1 to "dateiname" and it works also.
But =CELL("filename",A1) should work in any locale.
Of course in my German Excel it is =ZELLE("filename"; A1). But the function's name translation Excel is doing by default if the same file is opened in another locale or with another language version of Excel. The Excel file itself stores the English function names only.
Related
I have an .xltm template spreadsheet that I'm wondering if I can get a macro to populate the "save as" file name based on cell data, is this possible?
There are over 7 people who will have this spreadsheet, it's more of a form, and we are trying to figure out a way to keep the filenames uniform. I know there is the ThisWorkbook.BeforeSave, but I'm not really having any luck there. I just need it to make a file named something like $A$1 R $B$1 T $B$3.xlsx
how ever the problem im having is that one of the celss will have a function "Today()" and sometimes it will be a regular text the picture I included is off code that doeas work but only if the cell have a regular text in them but not a function, I quess it is due to it being a string or variable or something.
enter image description here
Any ideas on how to do this? anything helps thank very much.
I see from the image that you are working with Mac OS. The thing that comes to mind immediately is that the forward-slash character (/) is not allowed in a file name in Mac OS and by default, TODAY() is going to include the forward-slash character. Try using the replace function to switch it out for an underscore (_). So if your cell B7 uses the TODAY() function replace it with:
replace(range("B7").value,"/","_")
It also seems a bit strange to save an .xltm template as .xls file. Be sure you understand the workbook.saveas method including the fileformat argument
I think that part of your code should be:
ActiveWorkbook.saveAs strPath, xlExcel8
When a user manually enters formula in a sheet in the English version of Excel and sends this document to another user who has Excel in another version, the formula is automatically translated to the language in which the document is opened.
'Formula entered in Sheet1!B1 in the English Excel version
=VLOOKUP(A1,Sheet2!$A$1:$C$150,3,FALSE)
'Formula as shown in a Dutch Excel version
=VERT.ZOEKEN(A1;Sheet2!$A$1:$C$150;3;ONWAAR)
When I programmatically add a formula, in my English version, it would look like this:
Sub AddFormula()
ThisWorkbook.Worksheets("Sheet1").Cells(1, 2).Formula = "=VLOOKUP(A1,Sheet2!$A$1:$C$150,3,FALSE)"
End Sub
If I were to run this procedure on my English Version, then save the document and send it over to a user with another language, it would be fine as the formula is in the cell and thus translated to whatever language and locale the 2nd user uses.
My question is what happens when the 2nd user runs the procedure, in the Dutch (or other language for that matter) Excel with the formula in the code written in the EN-US format. Will it be translated or will it throw an error and in case of the latter, how would I solve that and make the formula insertion language proof?
In Excel vba the .Formula requires that the formula to be inserted be in EN-USA format. This is regardless of the local settings.
Excel will then translate it into the local vernacular when putting it in the sheet.
So no matter what the local settings it will work cross languages.
VBA also has the .FormulaLocal which allows the entry of the formula in the native language. But (as far as I know) it will not work cross different local settings.
I need to extract - in a cell - the last folder name where the active excel file is stored.
E.g. C:/Documents/Users/Accounting/May 2019/Expenses.xls
I want to extract/output the text "May 2019" in a specific cell by using a formula (not a macro).
Thank you in advance.
So, I went with using the CELL() function to get the full path and then cut out the last folder name.
See:
=TRIM(MID(SUBSTITUTE(CELL("filename",A1),"/",REPT(" ",999)),4*999-998,999))
Edit, As Ron pointed out that was fixed for the number of folders... This works around that:
See:
=TRIM(MID(SUBSTITUTE(CELL("filename",A1),"/",REPT(" ",999)),SUM(IF(CELL("filename",A1)<>"",LEN(CELL("filename",A1))-LEN(SUBSTITUTE(CELL("filename",A1),"/","")),0))*999-998,999))
Note:
Localization can mean ";" instead of "," and "\" instead of "/", so take care...
=ANNULLA.SPAZI(STRINGA.ESTRAI(SOSTITUISCI(CELLA("filename";A1);"\";RIPETI(" ";999));SOMMA(SE(CELLA("filename";A1)<>"";LUNGHEZZA(CELLA("filename";A1))-LUNGHEZZA(SOSTITUISCI(CELLA("filename";A1);"\";""));0))*999-998;999))
Localized Italian version of #SolarMike code's.
When a user manually enters formula in a sheet in the English version of Excel and sends this document to another user who has Excel in another version, the formula is automatically translated to the language in which the document is opened.
'Formula entered in Sheet1!B1 in the English Excel version
=VLOOKUP(A1,Sheet2!$A$1:$C$150,3,FALSE)
'Formula as shown in a Dutch Excel version
=VERT.ZOEKEN(A1;Sheet2!$A$1:$C$150;3;ONWAAR)
When I programmatically add a formula, in my English version, it would look like this:
Sub AddFormula()
ThisWorkbook.Worksheets("Sheet1").Cells(1, 2).Formula = "=VLOOKUP(A1,Sheet2!$A$1:$C$150,3,FALSE)"
End Sub
If I were to run this procedure on my English Version, then save the document and send it over to a user with another language, it would be fine as the formula is in the cell and thus translated to whatever language and locale the 2nd user uses.
My question is what happens when the 2nd user runs the procedure, in the Dutch (or other language for that matter) Excel with the formula in the code written in the EN-US format. Will it be translated or will it throw an error and in case of the latter, how would I solve that and make the formula insertion language proof?
In Excel vba the .Formula requires that the formula to be inserted be in EN-USA format. This is regardless of the local settings.
Excel will then translate it into the local vernacular when putting it in the sheet.
So no matter what the local settings it will work cross languages.
VBA also has the .FormulaLocal which allows the entry of the formula in the native language. But (as far as I know) it will not work cross different local settings.
I generated Excel file in my application in xlsx format. Unfortunately if I use English name of the function and my Excel is not set to English then Excel identifies it as bad function name. Simillar situation does not happen in xls format.
Is it any way to avoid this problem?
Configuration of Excel itself is not acceptable solution as client should not be forced to make changes in his environment.
Thanks in advance for any help
Excel has its own way for translating the formulas from every language to English. You should not take care of that, it does it quite well. Thus a file in Spanish Excel can be read in French Excel without further adjustments.
E.g., see the German formula "SUMME" in F1. It is translated by excel to "SUM", when you ask about it -> see the immediate window on the right.
The only thing you should avoid is formula like this:
activecell.FormulaR1C1Local= "=SUMME(Z(8)S(-2):Z(9)S(-2))", because it takes the local formula as a string and Excel cannot find a way to translate "SUMME" to "SUM".