Referencing Partial Folder Path

samuel.nunn

New Member
Joined
Feb 22, 2009
Messages
20
If starting on a cell such as D7, how do I reference a PARTIAL folder path listed in cell F7? The path will vary in how many subfolders it has. I simply want to reference the path MINUS the last subfolder. (e.g. \\foldler1\folder2\FolderIDon'tWantToReference, but remember the names of the subfolders and the number of subfolders will vary.)

I imagine offset and len will need to be used, I'm just not sure on the specifics.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Not certain which way round your cells are, but see if this is what you want.

Excel Workbook
DEF
7\\foldler1\folder2\\foldler1\folder2\FolderIDon'tWantToReference
Path
 
Upvote 0
Thanks, but let me clarify a little.

I'll start by giving a little background. I've created a program that allows users to search any given path and then choose to move or zip certain folders. Moving a folder works fine, and so does zipping a folder. However, after a folder is zipped it will not show up in future queries by this program since this program only searches for folders (zipped folders are considered individual files).

I want those zipped files to show up, so I am aiming to create a Macro to automatically place that zipped file into a folder called "FolderName_ZIPPED".



Here is the code I'm trying to use:

Code:
Dim fso As Object
        Dim file As String, sfol As String, dfol As String
        file = cell.Offset(0, 2).Value & ".zip"  ' This will already be created
        sfol =  ' This is the source folder.  The zipped file will appear in _ 'C:\Documents and Settings\kq146c\My Documents\Sweeper Test\, NOT _ 'C:\Documents and Settings\kq146c\My Documents\Sweeper Test\New 'Folder (2) _ 
'since the "New Folder (2)" was what was actually zipped.  How _
'do I tell it  not to reference the last folder?  Some kind of len function? _ 'Can I tell it to somehow subtract from column F what is in column E?
        dfol =  ' This is the destination folder.  Same concept as above. _
'I need it to reference the full path minus the last folder.  And then have _
'it create a folder in that path.  The naming of the new folder should be _
'simple enough: cell.offset(0, 2) & "_ZIPPED".  It's just a matter placing _  'it in the correct folder.

        Set fso = CreateObject("Scripting.FileSystemObject")
        If Not fso.FileExists(sfol & file) Then
            MsgBox sfol & file & " does not exist!", vbExclamation, "Source File Missing"
        ElseIf Not fso.FileExists(dfol & file) Then
            fso.MoveFile (sfol & file), dfol
        Else
            MsgBox dfol & file & " already exists!", vbExclamation, "Destination File Exists"
        End If
Thanks!
Sam
 
Upvote 0
Sam

Without getting into the specifics of your code, see if this helps

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> myPath()<br>    <SPAN style="color:#00007F">Dim</SPAN> FPath <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, SPath <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br>    <br>    FPath = Range("F7").Value<br>    SPath = Left(FPath, InStrRev(FPath, "\"))<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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