Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default code to strip back (from the right) a directory but not the file name

I have a path
eg. s:\jobs\2003\12345\construction\file.xls

I want to find the code that strips a level of this path
out i.e. remove \construction. (Go up a directory)
eg. s:\jobs\2003\12345\file.xls

This is so my destination file can be automatically
relinked to a source file that is kept in the directory
above the current destination files directory.

Thank you very much
Chrissie.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default code to strip back (from the right) a directory but not the file name

Chrissie,

Try something like the following:

Dim Pos1 As Long
Dim Pos2 As Long
Dim S As String
S = "s:\jobs\2003\12345\construction\file.xls"
Pos1 = InStrRev(S, "\", -1, vbTextCompare)
Pos2 = InStrRev(S, "\", Pos1 - 1, vbTextCompare)
If Pos2 0 Then
S = Left(S, Pos2 - 1) & Mid(S, Pos1)
End If
Debug.Print S


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com



"chrissie frisbee" wrote in message
...
I have a path
eg. s:\jobs\2003\12345\construction\file.xls

I want to find the code that strips a level of this path
out i.e. remove \construction. (Go up a directory)
eg. s:\jobs\2003\12345\file.xls

This is so my destination file can be automatically
relinked to a source file that is kept in the directory
above the current destination files directory.

Thank you very much
Chrissie.





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default code to strip back (from the right) a directory but not the file name

s:\jobs\2003\12345\construction\file.xls

to go up one directory use two dots.

s:\jobs\2003\12345\construction\..\file.xls

so
sPath = Thisworkbook.Path & "\..\"
sName = sPath & "file.xls"

--
Regards,
Tom Ogilvy


"chrissie frisbee" wrote in message
...
I have a path
eg. s:\jobs\2003\12345\construction\file.xls

I want to find the code that strips a level of this path
out i.e. remove \construction. (Go up a directory)
eg. s:\jobs\2003\12345\file.xls

This is so my destination file can be automatically
relinked to a source file that is kept in the directory
above the current destination files directory.

Thank you very much
Chrissie.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strip Flat File Table into less entries msnyc07 Excel Worksheet Functions 6 December 26th 09 10:40 AM
VB Code for a directory Marie Bayes Excel Discussion (Misc queries) 9 January 25th 07 01:12 PM
file save error: the file or directory cannot be created dublg Excel Discussion (Misc queries) 1 September 25th 06 07:07 PM
Code to raise Directory request box ANDYGM Excel Worksheet Functions 2 April 10th 06 11:47 AM
How do I strip a XML file to Excel? skuba Excel Discussion (Misc queries) 1 January 31st 06 06:24 PM


All times are GMT +1. The time now is 01:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"