Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting folder paths
All,
I have the following line of code which gets the full path (iPath) of a file (iFile) from a Root directory (sRoot) Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1, FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1)) I want to split it, so that the first folder in the path is displayed under iPathCol1 and the remainder of the path is displayed in iPathCol2. I don't understand the part after the equals sign! Can provide a solution for me. Thanks in advance. DDawson |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting folder paths
Presumably FindBack works from the end to find a \?
What is sRoot? -- HTH Bob Phillips (there's no email, no snail mail, but somewhere should be gmail in my addy) "dd" <dd.dd wrote in message ... All, I have the following line of code which gets the full path (iPath) of a file (iFile) from a Root directory (sRoot) Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1, FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1)) I want to split it, so that the first folder in the path is displayed under iPathCol1 and the remainder of the path is displayed in iPathCol2. I don't understand the part after the equals sign! Can provide a solution for me. Thanks in advance. DDawson |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting folder paths
Bob
sRoot is a string in the module code containing the startPath startPath is also a string. Function LoopFolders(startPath As String, _ Optional filetype As String = "RES File", _ Optional subfolders As Boolean = True) ' Create named Ranges, for the appropriate columns in Row 8 of Worksheet iPathCol = Range("firstPath").Column iFileCol = Range("firstFile").Column iLinkCol = Range("firstLink").Column iFile = Range("firstpath").Row sRoot = startPath '-- root is a named cell in the worksheet path is a named cell in the worksheet I think FindBack must find the first \ after the root, because there are several backslashes in the path after the root. I notice when I miss the \ after the root it adds it to the start of the path cells. When I add the \ to the root it dissapears from the cells. "Bob Phillips" wrote in message ... Presumably FindBack works from the end to find a \? What is sRoot? -- HTH Bob Phillips (there's no email, no snail mail, but somewhere should be gmail in my addy) "dd" <dd.dd wrote in message ... All, I have the following line of code which gets the full path (iPath) of a file (iFile) from a Root directory (sRoot) Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1, FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1)) I want to split it, so that the first folder in the path is displayed under iPathCol1 and the remainder of the path is displayed in iPathCol2. I don't understand the part after the equals sign! Can provide a solution for me. Thanks in advance. DDawson |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting folder paths
I thought it was something like that. So isn't sRoot the first folder that
you want? -- HTH Bob Phillips (there's no email, no snail mail, but somewhere should be gmail in my addy) "dd" <dd.dd wrote in message ... Bob sRoot is a string in the module code containing the startPath startPath is also a string. Function LoopFolders(startPath As String, _ Optional filetype As String = "RES File", _ Optional subfolders As Boolean = True) ' Create named Ranges, for the appropriate columns in Row 8 of Worksheet iPathCol = Range("firstPath").Column iFileCol = Range("firstFile").Column iLinkCol = Range("firstLink").Column iFile = Range("firstpath").Row sRoot = startPath '-- root is a named cell in the worksheet path is a named cell in the worksheet I think FindBack must find the first \ after the root, because there are several backslashes in the path after the root. I notice when I miss the \ after the root it adds it to the start of the path cells. When I add the \ to the root it dissapears from the cells. "Bob Phillips" wrote in message ... Presumably FindBack works from the end to find a \? What is sRoot? -- HTH Bob Phillips (there's no email, no snail mail, but somewhere should be gmail in my addy) "dd" <dd.dd wrote in message ... All, I have the following line of code which gets the full path (iPath) of a file (iFile) from a Root directory (sRoot) Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1, FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1)) I want to split it, so that the first folder in the path is displayed under iPathCol1 and the remainder of the path is displayed in iPathCol2. I don't understand the part after the equals sign! Can provide a solution for me. Thanks in advance. DDawson |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting folder paths
Bob
sRoot is the value that I type into the worksheet in the cell named "root" The full path is input in the worksheet the the cell named "firstPath" Instead of havingthe full path in one cell I would like to break it so that the first directory (after the root) is input in a cell named firstPath and the remainder of the path is input in the next cell named secondPath. Regards Dylan "Bob Phillips" wrote in message ... I thought it was something like that. So isn't sRoot the first folder that you want? -- HTH Bob Phillips (there's no email, no snail mail, but somewhere should be gmail in my addy) "dd" <dd.dd wrote in message ... Bob sRoot is a string in the module code containing the startPath startPath is also a string. Function LoopFolders(startPath As String, _ Optional filetype As String = "RES File", _ Optional subfolders As Boolean = True) ' Create named Ranges, for the appropriate columns in Row 8 of Worksheet iPathCol = Range("firstPath").Column iFileCol = Range("firstFile").Column iLinkCol = Range("firstLink").Column iFile = Range("firstpath").Row sRoot = startPath '-- root is a named cell in the worksheet path is a named cell in the worksheet I think FindBack must find the first \ after the root, because there are several backslashes in the path after the root. I notice when I miss the \ after the root it adds it to the start of the path cells. When I add the \ to the root it dissapears from the cells. "Bob Phillips" wrote in message ... Presumably FindBack works from the end to find a \? What is sRoot? -- HTH Bob Phillips (there's no email, no snail mail, but somewhere should be gmail in my addy) "dd" <dd.dd wrote in message ... All, I have the following line of code which gets the full path (iPath) of a file (iFile) from a Root directory (sRoot) Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1, FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1)) I want to split it, so that the first folder in the path is displayed under iPathCol1 and the remainder of the path is displayed in iPathCol2. I don't understand the part after the equals sign! Can provide a solution for me. Thanks in advance. DDawson |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting folder paths
Bob,
Function FindBack(text As String, char As String) As Long Dim i As Long ' This is the InstRev emulator, it works backwards along a string ' to find a specified character. For i = Len(text) To 1 Step -1 If Mid(text, i, 1) = char Then FindBack = i Exit For End If Next i End Function "Bob Phillips" wrote in message ... Presumably FindBack works from the end to find a \? What is sRoot? -- HTH Bob Phillips (there's no email, no snail mail, but somewhere should be gmail in my addy) "dd" <dd.dd wrote in message ... All, I have the following line of code which gets the full path (iPath) of a file (iFile) from a Root directory (sRoot) Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1, FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1)) I want to split it, so that the first folder in the path is displayed under iPathCol1 and the remainder of the path is displayed in iPathCol2. I don't understand the part after the equals sign! Can provide a solution for me. Thanks in advance. DDawson |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Getting folder paths
Bob,
From the worksheet I've copied the present values as follows The root is a constant and is currently: P:\Jobs\5048337\Surveys\Trial Surveys\ The Path column contains various paths such as: Cathcart (Glasgow) Signal Box\Proforma\Fabric\ There will always be three folders in this path. The filenames are something like: 100205.pfm To repeat what I'm trying to do, I want to create two columns for the paths. So that the first part, i.e. the location (Cathcart...) is in the first column (for Autofiltering) and the remainder of the path is in the second. I hope this gives you enough to be able to help me with this. Dylan. and the remainder is in the second column. "Bob Phillips" wrote in message ... I thought it was something like that. So isn't sRoot the first folder that you want? -- HTH Bob Phillips (there's no email, no snail mail, but somewhere should be gmail in my addy) "dd" <dd.dd wrote in message ... Bob sRoot is a string in the module code containing the startPath startPath is also a string. Function LoopFolders(startPath As String, _ Optional filetype As String = "RES File", _ Optional subfolders As Boolean = True) ' Create named Ranges, for the appropriate columns in Row 8 of Worksheet iPathCol = Range("firstPath").Column iFileCol = Range("firstFile").Column iLinkCol = Range("firstLink").Column iFile = Range("firstpath").Row sRoot = startPath '-- root is a named cell in the worksheet path is a named cell in the worksheet I think FindBack must find the first \ after the root, because there are several backslashes in the path after the root. I notice when I miss the \ after the root it adds it to the start of the path cells. When I add the \ to the root it dissapears from the cells. "Bob Phillips" wrote in message ... Presumably FindBack works from the end to find a \? What is sRoot? -- HTH Bob Phillips (there's no email, no snail mail, but somewhere should be gmail in my addy) "dd" <dd.dd wrote in message ... All, I have the following line of code which gets the full path (iPath) of a file (iFile) from a Root directory (sRoot) Cells(iFile, iPathCol).Value = Mid(oFile.Path, Len(sRoot) + 1, FindBack(oFile.Path, "\") + 1 - (Len(sRoot) + 1)) I want to split it, so that the first folder in the path is displayed under iPathCol1 and the remainder of the path is displayed in iPathCol2. I don't understand the part after the equals sign! Can provide a solution for me. Thanks in advance. DDawson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Paths | New Users to Excel | |||
Save file in a new folder, but create folder only if folder doesn't already exist? | Excel Programming | |||
Help with filenames and paths. | Excel Discussion (Misc queries) | |||
XP and string paths | Excel Programming | |||
UNC Paths | Excel Programming |