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.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
42,254
Office Version
365
Platform
Windows
Not certain which way round your cells are, but see if this is what you want.

Excel Workbook
DEF
7\\foldler1\folder2\FolderIDon'tWantToReference
Path
 

samuel.nunn

New Member
Joined
Feb 22, 2009
Messages
20
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
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
42,254
Office Version
365
Platform
Windows
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>
 

Forum statistics

Threads
1,082,258
Messages
5,364,093
Members
400,779
Latest member
lumers

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top