I have paths in Excel column and I want extract filename in other cell without VBA.
/where/is/my/path/filename.txt
I would like extract "filename.txt"
I share with you my finds.
I find this site :
https://www.extendoffice.com/documents/excel/1431-excel-extract-filename-from-full-path.html
=MID(A1,FIND("*",SUBSTITUTE(A1,"\","*",LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))))+1,LEN(A1))
But doesn't work on french Excel that's why I translate for French users :
=STXT(A1;CHERCHE("$";SUBSTITUE(A1;"/";"$";NBCAR(A1)-NBCAR(SUBSTITUE(A1;"/";""))))+1;NBCAR(A1))
I change "\" to "/" because I have unix path.
This will help:
var url = "/where/is/my/path/filename.txt";
var filename = url.substring(url.lastIndexOf('/')+1);
alert(filename);
Related
i've been wondering if there's a way to to use the "GetFileName" to get the name from a path that exists in a cell instead of using a direct path eg below
Filename = fso.GetFileName(Worksheets("Setup").Cells(8, 2).Value)
instead of
FileName = FSO.GetFileName("C:\ExamplePath\ExampleFile.xls")
Thank you in advance for any hints
Say, I'm writing a VBA inside my excel file sample.xls. Now I want to get the full path of sample.xls in my VBA. How do I do it?
If you mean VBA, then you can use FullName, for example:
strFileFullName = ThisWorkbook.FullName
(updated as considered by the comments: the former used ActiveWorkbook.FullName could more likely be wrong, if other office files may be open(ed) and active. But in case you stored the macro in another file, as mentioned by user #user7296559 here, and really want the file name of the macro-using file, ActiveWorkbook could be the correct choice, if it is guaranteed to be active at execution time.)
this is a simple alternative that gives all responses, Fullname, Path, filename.
Dim FilePath, FileOnly, PathOnly As String
FilePath = ThisWorkbook.FullName
FileOnly = ThisWorkbook.Name
PathOnly = Left(FilePath, Len(FilePath) - Len(FileOnly))
strScriptFullname = WScript.ScriptFullName
strScriptPath = Left(strScriptFullname, InStrRev(strScriptFullname,"\"))
If you need path only this is the most straightforward way:
PathOnly = ThisWorkbook.Path
if you need path only without file name:
ActiveWorkbook.Path
it would return D:\Folder
if you need file path with file name also:
ActiveWorkbook.FullName
it would return D:\Folder\sample.xls
if you need file name only:
ActiveWorkbook.Name
it would return sample.xls
so if you want combine file path and file name to get full directory don't forget to add "" between. otherwise its simpler using .Path
ActiveWorkbook.FullName would be better I think, in case you have the VBA Macro stored in another Excel Workbook, but you want to get the details of the Excel you are editing, not where the Macro resides.
If they reside in the same file, then it does not matter, but if they are in different files, and you want the file where the Data is rather than where the Macro is, then ActiveWorkbook is the one to go for, because it deals with both scenarios.
There is a universal way to get this:
Function FileName() As String
FileName = Mid(Application.Caption, 1, InStrRev(Application.Caption, "-") - 2)
End Function
so i searched but didnt find something good for my use , i have a folder where i will import an excel file , this excel file will have a different name everytime how i can open it with vba , thank you
You can get the file name using the Dir function and multiple character (*) wildcard.
Const Path As String = "C:\Test"
Dim filename As String
filename = Dir(Path & "\*.xlsx")
If Len(filename) > 0 Then
' Do your work
' Remember 'filename' only holds the file name
' you will need to attach the rest of the path to get the full directory.
End If
Note: If there's only one file in the folder you will not have any issues, however if the folder contains multiple files (matching the above pattern), you will need to either loop or provide additional file name characters to the function.
An example:
File name: daily_report_20190404.xlsx
filename = Dir(Path & "\daily_report_*.xlsx")
Hope this helps.
I want to parse an xlsx file which contains hyperlinks on my node.js server.
I tried some xlsx parser in npm (like 'excel-parser', 'xlsx'), but I couldn't get the hyperlink values (only the text value).
Does anyone knows how to extract the hyperlink using node.js ?
If you dislike the existing solutions, you can always unzip the file (OfficeOpen XML files are zipped directories with sereval files in it), and parse the main part yourself in the search of links.
An old question, but one without an answer that I could easily find elsewhere after half an hour of looking.
The below code will read an XSLX and dump it to the console row by row: row.values will be plain text or an object with keys formula and result, the former being the hyperlink, the latter the visible text.
I've only just found exceljs so ymmv, but it seems straightforward and has a large, but not overwhelming, variety of options for getting the job done quickly.
const xl = require('exceljs');
const csvPath = 'NTA Transcripts.xlsx';
const workbook = new xl.Workbook();
await workbook.xlsx.readFile(csvPath);
const worksheet = workbook.getWorksheet(1);
worksheet.eachRow({ includeEmpty: true }, (row, rowNumber) => {
console.log("Row ", rowNumber, ": ", JSON.stringify(row.values, null, 2));
});
Say, I'm writing a VBA inside my excel file sample.xls. Now I want to get the full path of sample.xls in my VBA. How do I do it?
If you mean VBA, then you can use FullName, for example:
strFileFullName = ThisWorkbook.FullName
(updated as considered by the comments: the former used ActiveWorkbook.FullName could more likely be wrong, if other office files may be open(ed) and active. But in case you stored the macro in another file, as mentioned by user #user7296559 here, and really want the file name of the macro-using file, ActiveWorkbook could be the correct choice, if it is guaranteed to be active at execution time.)
this is a simple alternative that gives all responses, Fullname, Path, filename.
Dim FilePath, FileOnly, PathOnly As String
FilePath = ThisWorkbook.FullName
FileOnly = ThisWorkbook.Name
PathOnly = Left(FilePath, Len(FilePath) - Len(FileOnly))
strScriptFullname = WScript.ScriptFullName
strScriptPath = Left(strScriptFullname, InStrRev(strScriptFullname,"\"))
If you need path only this is the most straightforward way:
PathOnly = ThisWorkbook.Path
if you need path only without file name:
ActiveWorkbook.Path
it would return D:\Folder
if you need file path with file name also:
ActiveWorkbook.FullName
it would return D:\Folder\sample.xls
if you need file name only:
ActiveWorkbook.Name
it would return sample.xls
so if you want combine file path and file name to get full directory don't forget to add "" between. otherwise its simpler using .Path
ActiveWorkbook.FullName would be better I think, in case you have the VBA Macro stored in another Excel Workbook, but you want to get the details of the Excel you are editing, not where the Macro resides.
If they reside in the same file, then it does not matter, but if they are in different files, and you want the file where the Data is rather than where the Macro is, then ActiveWorkbook is the one to go for, because it deals with both scenarios.
There is a universal way to get this:
Function FileName() As String
FileName = Mid(Application.Caption, 1, InStrRev(Application.Caption, "-") - 2)
End Function