A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Word » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

search and replace



 
 
Thread Tools Display Modes
  #1  
Old April 22nd, 2010, 07:32 PM posted to microsoft.public.word.docmanagement
erica
external usenet poster
 
Posts: 53
Default 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  
Old April 22nd, 2010, 08:14 PM posted to microsoft.public.word.docmanagement
Herb Tyson [MVP]
external usenet poster
 
Posts: 3,614
Default 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  
Old April 23rd, 2010, 05:56 AM posted to microsoft.public.word.docmanagement
Graham Mayor
external usenet poster
 
Posts: 18,297
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:21 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.