Reputation: 23
I have a sheet which is the active sheet, and I would like to paste the name of the folder the excel sheet is contained in into cells in Excel. Is there a way to do this and if so how?
ie. how can I get the folder that the activeSheet is in? Is there a function called active folder or something?
Upvotes: 0
Views: 42
Reputation: 11986
Use ActiveWorkbook.Path. If the active workbook has not been saved, an empty string will be returned.
Sub FindFolder()
Dim strFolder As String
strFolder = ActiveWorkbook.Path
ActiveWorkbook.ActiveSheet.Range("A1").Value = strFolder
End Sub
Use the CELL function to get the full path, file name and sheet name. Then extract the folder using LEFT and FIND functions. If the active workbook has not been saved, a #VALUE! will be returned.
=LEFT(CELL("filename"),FIND("[",CELL("filename"))-1)
Upvotes: 1