search and replace

E

Erica

My question is about the search and replace function. I need to know if
there is a way to get rid of a string of characters, for example:

C:\tasking\Evidence\may\2010\final_report.doc

I need to delete everything before the "\" so that I just end up with the
filename. Is there a special function I can put in the find and replace so
that my end result is just the document (final_report.doc)?
 
H

Herb Tyson [MVP]

If it's always the same folder, it's a very simple matter. Just set Find
what: to

C:\tasking\Evidence\may\2010\

leave Replace with: blank, and click Replace All.

If the disk is always C and if there are always the same number of \'s in
the structure, you can try the following, with Use wildcards (click More to
see this option) turned on:

Find what:C:\\*\\*\\*\\*\\

Note: when searching for "\" with wildcards turned on, you have to double
the \ in order to prevent Word from interpreting \ as a special character.

If there aren't always the same number of \'s, I would start with the
maximum number, then trim a *\\ set to catch the next lower number, and keep
removing *\\ sets until you've handled all of the items in the list.
 
G

Graham Mayor

If this is the filename of the document you are working on, then simply
insert a filename field without the \p switch.
or insert the filename of the document with a macro eg

Sub InsertFilenameOnly()
With ActiveDocument
If Len(.Path) = 0 Then .Save
Selection.TypeText .name
End With
End Sub

If the path relates to another document and is thus simply a string, you can
do that with a macro - regardless of the length of the path eg

Sub RemovePath()
Dim oRng As Range
Set oRng = Selection.Range
If Len(oRng) = 0 Then
MsgBox "Nothing selected!"
Set oRng = Nothing
Exit Sub
End If
oRng.End = oRng.Start + InStrRev(oRng.Text, "\")
oRng.Delete
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top