Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Extract Path From String

Hi All,

If I have the following string assigned to var_full "C:\my documents\test
folder\test doc.doc"

What is the best way to extract the path from the above string so that the
output is "C:\my documents\test folder"

The output string needs to NOT finish in a backslash.

The solution also needs to be able to cope with any number of folder
hierarchies.

Any ideas?

Ta

Andi


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Extract Path From String

What version of excel are you using?

xl2k+

Option Explicit
Sub testme()

Dim myStr As String
Dim myPath as string

myStr = "C:\my documents\test folder\test doc.doc"

myPath = Left(myStr, InStrRev(myStr, "\") - 1)

MsgBox myPath

End Sub

before xl2k:

Option Explicit
Sub testme()

Dim myStr As String
Dim myPath As String
Dim iCtr As Long

myStr = "C:\my documents\test folder\test doc.doc"

For iCtr = Len(myStr) To 1 Step -1
If Mid(myStr, iCtr, 1) = "\" Then
myPath = Left(myStr, iCtr - 1)
Exit For
End If
Next iCtr

MsgBox myPath
End Sub

Andibevan wrote:

Hi All,

If I have the following string assigned to var_full "C:\my documents\test
folder\test doc.doc"

What is the best way to extract the path from the above string so that the
output is "C:\my documents\test folder"

The output string needs to NOT finish in a backslash.

The solution also needs to be able to cope with any number of folder
hierarchies.

Any ideas?

Ta

Andi


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Extract Path From String

It needs to be compatable with at least XL2000.

"Dave Peterson" wrote in message
...
What version of excel are you using?

xl2k+

Option Explicit
Sub testme()

Dim myStr As String
Dim myPath as string

myStr = "C:\my documents\test folder\test doc.doc"

myPath = Left(myStr, InStrRev(myStr, "\") - 1)

MsgBox myPath

End Sub

before xl2k:

Option Explicit
Sub testme()

Dim myStr As String
Dim myPath As String
Dim iCtr As Long

myStr = "C:\my documents\test folder\test doc.doc"

For iCtr = Len(myStr) To 1 Step -1
If Mid(myStr, iCtr, 1) = "\" Then
myPath = Left(myStr, iCtr - 1)
Exit For
End If
Next iCtr

MsgBox myPath
End Sub

Andibevan wrote:

Hi All,

If I have the following string assigned to var_full "C:\my documents\test
folder\test doc.doc"

What is the best way to extract the path from the above string so that
the
output is "C:\my documents\test folder"

The output string needs to NOT finish in a backslash.

The solution also needs to be able to cope with any number of folder
hierarchies.

Any ideas?

Ta

Andi


--

Dave Peterson



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
Relative Path in Connection String Breunus Excel Discussion (Misc queries) 2 July 29th 09 05:10 PM
How to extract only file name from folder path string in Excel? JayKay Excel Worksheet Functions 1 March 20th 09 04:57 PM
Extract full path given filename Kim J. Excel Programming 3 October 14th 04 04:38 AM
chdir not accepting string for path Alan Excel Programming 1 October 13th 04 06:18 PM
Getting a String Path from a browser... Juan Sanchez Excel Programming 9 July 23rd 04 05:28 PM


All times are GMT +1. The time now is 11:03 PM.

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"