Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Need help editing a string

The code below prompts the user for a folder then trys to use that folder
path to name a worksheet. Of course it doesn't work because it has invalid
characters for naming a worksheet. What I need to do is cut the folder path
down to just the name of the last folder ie.. c:\documents and
settings\user\desktop would get cut down to just desktop. I have no idea
where to start.

Thanks in advance

Steve


With Application.FileDialog(msoFileDialogFolderPicker)
.Show

MsgBox .SelectedItems(1)
Dim curwb As Workbook
Dim curws As Worksheet
MyFolder = "c:\"
Set curwb = ActiveWorkbook
Set curws = curwb.Worksheets.Add
curws.Name = .SelectedItems(1)
Me.txtSelectedFolder = .SelectedItems(1)

End With


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Need help editing a string

Hi Steve,

Assuming that you are using xl2k or later, try something like:

Sub Tester()
Dim sStr As String
Dim iPos As Long

sStr = "c:\documents andsettings\user\desktop"
iPos = InStrRev(sStr, "\")
sStr = Mid(sStr, iPos + 1)
MsgBox sStr

End Sub


---
Regards,
Norman



"Steve Roberts" wrote in message
...
The code below prompts the user for a folder then trys to use that folder
path to name a worksheet. Of course it doesn't work because it has invalid
characters for naming a worksheet. What I need to do is cut the folder
path down to just the name of the last folder ie.. c:\documents and
settings\user\desktop would get cut down to just desktop. I have no idea
where to start.

Thanks in advance

Steve


With Application.FileDialog(msoFileDialogFolderPicker)
.Show

MsgBox .SelectedItems(1)
Dim curwb As Workbook
Dim curws As Worksheet
MyFolder = "c:\"
Set curwb = ActiveWorkbook
Set curws = curwb.Worksheets.Add
curws.Name = .SelectedItems(1)
Me.txtSelectedFolder = .SelectedItems(1)

End With



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Need help editing a string


or this...

Function GetLastPart(sPath)
GetLast = Split(sPath, "\")(UBound(Split(sPath, "\")))
End Function

Tim.

"Steve Roberts" wrote in message
...
The code below prompts the user for a folder then trys to use that
folder path to name a worksheet. Of course it doesn't work because
it has invalid characters for naming a worksheet. What I need to do
is cut the folder path down to just the name of the last folder ie..
c:\documents and settings\user\desktop would get cut down to just
desktop. I have no idea where to start.

Thanks in advance

Steve


With Application.FileDialog(msoFileDialogFolderPicker)
.Show

MsgBox .SelectedItems(1)
Dim curwb As Workbook
Dim curws As Worksheet
MyFolder = "c:\"
Set curwb = ActiveWorkbook
Set curws = curwb.Worksheets.Add
curws.Name = .SelectedItems(1)
Me.txtSelectedFolder = .SelectedItems(1)

End With



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Need help editing a string

Hi Tim,

Just to alert you to a minor typo:

GetLast = Split(sPath, "\")(UBound(Split(sPath, "\")))


should be:

GetLastPart = Split(sPath, "\")(UBound(Split(sPath, "\")))


---
Regards,
Norman



"Tim Williams" <saxifrax@pacbell*dot*net wrote in message
...

or this...

Function GetLastPart(sPath)
GetLast = Split(sPath, "\")(UBound(Split(sPath, "\")))
End Function

Tim.

"Steve Roberts" wrote in message
...
The code below prompts the user for a folder then trys to use that folder
path to name a worksheet. Of course it doesn't work because it has
invalid characters for naming a worksheet. What I need to do is cut the
folder path down to just the name of the last folder ie.. c:\documents
and settings\user\desktop would get cut down to just desktop. I have no
idea where to start.

Thanks in advance

Steve


With Application.FileDialog(msoFileDialogFolderPicker)
.Show

MsgBox .SelectedItems(1)
Dim curwb As Workbook
Dim curws As Worksheet
MyFolder = "c:\"
Set curwb = ActiveWorkbook
Set curws = curwb.Worksheets.Add
curws.Name = .SelectedItems(1)
Me.txtSelectedFolder = .SelectedItems(1)

End With





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Need help editing a string

That worked Great! Thanks.


"Norman Jones" wrote in message
...
Hi Steve,

Assuming that you are using xl2k or later, try something like:

Sub Tester()
Dim sStr As String
Dim iPos As Long

sStr = "c:\documents andsettings\user\desktop"
iPos = InStrRev(sStr, "\")
sStr = Mid(sStr, iPos + 1)
MsgBox sStr

End Sub


---
Regards,
Norman



"Steve Roberts" wrote in message
...
The code below prompts the user for a folder then trys to use that folder
path to name a worksheet. Of course it doesn't work because it has
invalid characters for naming a worksheet. What I need to do is cut the
folder path down to just the name of the last folder ie.. c:\documents
and settings\user\desktop would get cut down to just desktop. I have no
idea where to start.

Thanks in advance

Steve


With Application.FileDialog(msoFileDialogFolderPicker)
.Show

MsgBox .SelectedItems(1)
Dim curwb As Workbook
Dim curws As Worksheet
MyFolder = "c:\"
Set curwb = ActiveWorkbook
Set curws = curwb.Worksheets.Add
curws.Name = .SelectedItems(1)
Me.txtSelectedFolder = .SelectedItems(1)

End With







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Need help editing a string

Thanks Norman

Tim

"Norman Jones" wrote in message
...
Hi Tim,

Just to alert you to a minor typo:

GetLast = Split(sPath, "\")(UBound(Split(sPath, "\")))


should be:

GetLastPart = Split(sPath, "\")(UBound(Split(sPath, "\")))


---
Regards,
Norman



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
Change 3 letter text string to a number string Pete Excel Discussion (Misc queries) 3 December 31st 07 07:47 PM
to search for a string and affect data if it finds the string? Shwaman Excel Worksheet Functions 1 January 11th 06 12:56 AM
Importing/Exporting text files and string editing Slick Willie Excel Programming 1 September 23rd 04 12:24 AM
Passing a String in Array to Range as String [email protected] Excel Programming 2 September 1st 04 01:13 AM
Create a formula into a String then assign string to a cell Myrna Larson[_2_] Excel Programming 6 August 23rd 03 09:42 PM


All times are GMT +1. The time now is 05:24 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"