Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
checkQ checkQ is offline
external usenet poster
 
Posts: 9
Default I would like to find and replace a list of words with numbers

I have a word file with over 99 pages. Each page has a client name on it. I
would like to find each client name and print a code number at the top of
the page that corresponds to that specific client. maybe it could be in the
page number or it could be anywhere in the upper left side of the page. I
think a macro would work.

Thanks a million

  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default I would like to find and replace a list of words with numbers

On Tue, 30 Sep 2008 17:33:00 -0700, checkQ
wrote:

I have a word file with over 99 pages. Each page has a client name on it. I
would like to find each client name and print a code number at the top of
the page that corresponds to that specific client. maybe it could be in the
page number or it could be anywhere in the upper left side of the page. I
think a macro would work.

Thanks a million


A macro could do it, but you have to supply it somehow with a list of the client
names and the corresponding code numbers. Do you already have that list? If so,
what format is it in?

When you say that each page has the client name on it, is that just plain typed
text, or is it formatted somehow? With a bookmark, or a specific style, or in
some distinctive font? Or would the macro just have to search for the name?

The code number would have to be placed somewhere specific. You can't just float
it "somewhere in the upper left side of the page" (well, I suppose it could be
put in a text box and positioned anywhere, but that isn't very stable). Would
you want it in a regular text paragraph above the first text on the page, or in
the header (that isn't the page number, but it is the area where the page number
often is placed)?

In order to write a macro (which is just a literal set of instructions) you have
to make decisions about all these things first. Computers are very stupid about
vague instructions like "put it somewhere over there".


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
  #3   Report Post  
Posted to microsoft.public.word.docmanagement
checkQ checkQ is offline
external usenet poster
 
Posts: 9
Default I would like to find and replace a list of words with numbers

List of Names CODE NUMBER
Marcus Bowes 12
Norman Hilton 13
Nancy Bates 2
Lori Felts 5

Each page in the word document has a different name ie Marcus Bowes. the
names are not formatted in any way. In the upper left hand side of the corner
I would like the number 12 to appear. Or maybe at the top of the page. This
would be a specific location of course, not "somewhere over there"
  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default I would like to find and replace a list of words with numbers

On Wed, 1 Oct 2008 07:50:01 -0700, checkQ
wrote:

List of Names CODE NUMBER
Marcus Bowes 12
Norman Hilton 13
Nancy Bates 2
Lori Felts 5

Each page in the word document has a different name ie Marcus Bowes. the
names are not formatted in any way. In the upper left hand side of the corner
I would like the number 12 to appear. Or maybe at the top of the page. This
would be a specific location of course, not "somewhere over there"


When I wrote "you have to supply it somehow with a list of the client
names and the corresponding code numbers. Do you already have that list? If so,
what format is it in?" I meant is stored as a text file, or as a table in a Word
document, or in an Excel sheet, or just typed the way you showed it above? In
other words, what is the macro going to have to do in order to get hold of that
information?

One more question that has a bearing on how the code number is inserted: What
separates the pages in this document? Are there section breaks, manual page
breaks, or nothing? (If you aren't sure, temporarily change the view to Normal
[called Draft view in Word 2007] and look at the dotted line that represents the
boundary between the pages -- does it say "Page Break" or "Section Break" or
nothing?

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
  #5   Report Post  
Posted to microsoft.public.word.docmanagement
checkQ checkQ is offline
external usenet poster
 
Posts: 9
Default I would like to find and replace a list of words with numbers

The names are in text form.

What the code should do is look for Marcus Bowes and replace it with the
number 12. Or instead of replacing Marcus Bowes with 12 it could insert the
number 12 at the top of the page. This would be two separate macros in case
the other is not doable.

The body of the page would have Marcus Bowes and at the top of the page it
would have 12. On the next page where we have Norman Hilton, the macro would
search for the name Norman Hilton and insert the number 13. On the page where
there is Nancy Bates the macro would insert the number 2.

Or instead of inserting the number 2 at the top of the page, the macro would
search for Nancy Bates and replace Nancy Bates with the number 2. Of course I
could us the "find and Replace" option but I can only do that one at a time
for 99 pages.

The pages are separated by "page break"


  #6   Report Post  
Posted to microsoft.public.word.docmanagement
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default I would like to find and replace a list of words with numbers

On Wed, 1 Oct 2008 17:46:03 -0700, checkQ
wrote:

The names are in text form.

What the code should do is look for Marcus Bowes and replace it with the
number 12. Or instead of replacing Marcus Bowes with 12 it could insert the
number 12 at the top of the page. This would be two separate macros in case
the other is not doable.

The body of the page would have Marcus Bowes and at the top of the page it
would have 12. On the next page where we have Norman Hilton, the macro would
search for the name Norman Hilton and insert the number 13. On the page where
there is Nancy Bates the macro would insert the number 2.

Or instead of inserting the number 2 at the top of the page, the macro would
search for Nancy Bates and replace Nancy Bates with the number 2. Of course I
could us the "find and Replace" option but I can only do that one at a time
for 99 pages.

The pages are separated by "page break"


Hmm... we're getting closer. Does "The names are in text form" mean they're in a
file with a .txt extension? If so, what is the path and file name of that file?
What separates the names from the code numbers -- are there tab characters as in
the sample you posted earlier, in some cases with spaces also, or something
else?

And are you sure it's going to be OK to completely replace the name on the
document page, so the name doesn't appear any more and only the code number
appears?

The reason I asked about the page break was to find out whether the document is
separated into "sections" (in Word lingo, meaning areas between section breaks),
which is typical output of a mail merge. It is not, which means that the code
numbers cannot be put into the header area because it would show the same value
on every page.

On the chance that I'm close to understanding what you want, the following macro
might do it. You'll have to replace "code.txt" in the macro with the actual name
of the text file containing the names and codes; and either put that file in
your Documents folder or change the Options.DefaultFilePath(wdDocumentsPath) to
the actual path where the file exists.

Sub NamesToCodes()
Dim WorkFile As Document
Dim CodeFile As String
Dim CodeLine As String
Dim LastSpacePos As Long
Dim CodeArray() As String
Dim ArrayLen As Long
Dim idx As Long
Dim SearchRg As Range

Set WorkFile = ActiveDocument

' Load the array with data from codefile
' (in this example, a file "codes.txt" in the
' Documents folder
CodeFile = Options.DefaultFilePath(wdDocumentsPath) _
& "\codes.txt"
ArrayLen = 0
Open CodeFile For Input As #1
While Not EOF(1)
Line Input #1, CodeLine

' assume that there is at least one tab
' between the name and the code number, and
' no tabs after the number
LastSpacePos = InStrRev(CodeLine, vbTab)

If LastSpacePos 0 Then
ReDim Preserve CodeArray(1, ArrayLen)
CodeArray(0, ArrayLen) = Replace( _
Trim(Left(CodeLine, LastSpacePos - 1)), _
vbTab, "")
CodeArray(1, ArrayLen) = _
Trim(Right(CodeLine, Len(CodeLine) - LastSpacePos))
ArrayLen = ArrayLen + 1
End If
Wend
Close #1

' Replace the first occurrence of each name (if found)
' with the corresponding code
For idx = 0 To ArrayLen - 1
Set SearchRg = WorkFile.Range
With SearchRg.Find
.Text = CodeArray(0, idx)
.Replacement.Text = CodeArray(1, idx)
.Forward = True
.Format = False
.Wrap = wdFindStop
.Execute Replace:=wdReplaceOne
End With
Next idx
End Sub

See http://www.gmayor.com/installing_macro.htm if you need instructions.


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
  #7   Report Post  
Posted to microsoft.public.word.docmanagement
shapiro shapiro is offline
external usenet poster
 
Posts: 7
Default I would like to find and replace a list of words with numbers

Ouch. I think this looks like what I am looking for. I will try it out and
let you know how it worked out. Thanks.

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I would like to find and rplace a list of words with code numbers checkQ Microsoft Word Help 0 September 30th 08 07:42 PM
Find and Replace all words that have a certain value in them, not just the value itself. El Capitán de las Albondigas Microsoft Word Help 1 September 30th 07 02:27 AM
How do i find and replace words in parenthesis? Bob in Arizona Microsoft Word Help 5 September 1st 06 06:31 AM
Trying to replace words with fields using Find/Replace mbleyle Microsoft Word Help 2 March 29th 06 11:35 PM
Find/ Replace is auto-capping the words I want to replace with Graham Mayor Microsoft Word Help 8 January 27th 06 01:39 AM


All times are GMT +1. The time now is 12:04 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"