If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
search and replace
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)? |
#2
|
|||
|
|||
search and replace
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. -- Herb Tyson MS MVP Author of the Word Bible Blog: http://word.herbtyson.com Web: http://www.herbtyson.com "Erica" wrote in message ... 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)? |
#3
|
|||
|
|||
search and replace
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 My web site www.gmayor.com Word MVP web site http://word.mvps.org "Erica" wrote in message ... 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)? |
Thread Tools | |
Display Modes | |
|
|