PDA

View Full Version : Replace part of ComboBox string



jolivanes
09-29-2006, 11:04 PM
How do I replace the part of a ComboBox string that is between the last backwards slash (\) and the following period (.) with the text in a TextBox and put the result in the first empty cell in column B?
ComboBox: C:\My Documents\John\My Pictures\Img_0001.jpg
TextBox: xld and johnske
Result: C:\My Documents\John\My Pictures\xld and johnske.jpg

See http://www.ozgrid.com/forum/showthread.php?t=57976

Thank you in advance
See attached workbook

John

mdmackillop
09-30-2006, 01:38 AM
Hi John

Private Sub CommandButton12_Click()
Dim fPath As String, Ln As Long, OldName As String
Dim NewName As String

NewName = TextBox2.Text
OldName = cbbFiles.Text

Ln = Len(Split(OldName, "\")(UBound(Split(OldName, "\"))))
fPath = Left(OldName, Len(OldName) - Ln)
Cells(Rows.Count, 2).End(xlUp).Offset(1) = fPath & NewName & Right(OldName, 4)
End Sub

jolivanes
09-30-2006, 08:51 AM
mdmackillop.
Fantastic. Thank you very much. All that's left now for me is to change the CommandButton11 language to column A.
Thanks again.
John

jolivanes
10-01-2006, 09:53 AM
mdmackillop.
Everythings works great on both Excel 2000 (Win98) and Excel 2003 (XP Prof). However, on an Excel 2002 (XP Prof) computer, it comes up that it can't find pictures. The folder I choose definitly has pictures in it. As far as I can see, all the settings are the same. Security is set to medium like on the other computers. Would that be a setting somewhere or in the macro language?
Thank you very much
John

mdmackillop
10-01-2006, 09:59 AM
Hi John,
The code only runs when you click the button. It can't affect the ability of your form to load the picture files. Don't know what to suggest.

jolivanes
10-01-2006, 01:12 PM
Hi mdmackillop.
The strange thing is that when I go in another computer, find the file on the rogue computer through the LAN and open it on the other computer, I get the pictures stored on the rogue computer. I keep on plodding away at it for a while.
Thanks again for your help.
John