Need a variable to return current folder name

Koreno

New Member
Joined
May 8, 2015
Messages
24
I need a variable to return the name of the folder the open workbook is in.

I tried the following 2 but they are not what I need.

This one results in Y:\AAL\+Templates
Code:
Dim MyPath As String
MyPath = ActiveWorkbook.Path


This one results in Y:\AAL\+Templates\TO TEMPLATE_NEW.xlsm
Code:
Dim MyCompletePath As String
MyCompletePath = ActiveWorkbook.FullName


The result i need is just...

+Templates

None of the folders before it. The reason for this is that I am have a code that does a saveas and names the file. I need the name of the file to start with the name of the folder it is inside of.
In this case....

+TemplatesQuote.xlsx
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try this...

Code:
[color=darkblue]Dim[/color] MyFolder [color=darkblue]As[/color] [color=darkblue]String[/color]
MyFolder = Mid(ActiveWorkbook.Path, InStrRev(ActiveWorkbook.Path, Application.PathSeparator) + 1)
 
Upvote 0
This will work for what you want...

Code:
Split(ActiveWorkbook.Path, "\")(Ubound(Split(ActiveWorkbook.Path, "\")))

HTH
 
Upvote 0

Forum statistics

Threads
1,215,019
Messages
6,122,707
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top