Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

LBound and UBound

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg - 18 Mar 2005 14:57 GMT
Hello Masters,

I was using the following lines of code to supply the ".Find" text in a
macro.  The words to be found are in single column table with the
heading "Find" and stored in another document.

For i = LBound(ListArray) To UBound(ListArray) - 1 Step 2
 With rngstory.Find
   .ClearFormatting
   .Replacement.ClearFormatting
   .Text = ListArray(i)
   On Error GoTo Done
   .Replacement.Text = Format(Left(ListArray(i), 1), ">") &
Right(ListArray(i), Len(ListArray(i)) - 1)
   .Replacement.Font.Bold = True
   .Execute Replace:=wdReplaceAll
 End With
Next i
Done:

The object of the macro was to look for these words in a document.  If
found, First Cap the word and bold the word.
It works, but there are/were two problemns.  First, if the table had
more rows than words and error is generated at the .Replacement line.
Error handling is my weakest link.  I got around this by simply
skipping out of the macro with the On Error GoTo line.  Is this the
right way?

Second problem was the heading in the table.  If the word "find" was
included in the document text it was being processed as well.  How do
you tell the macro to skip the first row?  This is what I came up with:

For i = 2 To UBound(ListArray) - 1 Step 2

but I don't really understand why or how it works.  Thanks for any
enlightenment you can offer.
Helmut Weber - 18 Mar 2005 17:40 GMT
Hi Greg,

is listarray an array filled with cell contents?
What is step 2 good for?
Process only each second entry?
Do you feed empty cells into the listarray?
Not that I think so, but can't think of something else either.

LBound and UBound?

Well, there must be a question behind the question!

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/

>Hello Masters,
>
[quoted text clipped - 32 lines]
>but I don't really understand why or how it works.  Thanks for any
>enlightenment you can offer.
Greg - 18 Mar 2005 18:08 GMT
Helmut

I have a macro that will perform a multiword find and replace operation
where the Find and Replace words are listed in a two column table
stored as a separate document.  The Find words are listed on the left
under a column headed FIND.  The Replace words on the right.  These
words are used to build an array.  Like this:

Set WordList = Documents.Open(fileName:="C:\Find and Replace List.doc")
ListArray = WordList.Tables(1).Range.Text
ListArray = Split(ListArray, Chr(13) & Chr(7))
WordList.Close

The Find and Replace code is:

For i = LBound(ListArray) To UBound(ListArray) - 1 Step 3
 With rngstory.Find
   .ClearFormatting
   .Replacement.ClearFormatting
   .Text = ListArray(i)
   .Replacement.Text = ListArray(i + 1)
   .Execute Replace:=wdReplaceAll
 End With
Next i

For the project I am playing with now, I only need FIND words and so I
adapted the code as I posted earlier.  While experimenting with this I
noticed that if my text to be processes contains the word FIND (my
column header) then it is also processed which is what I don't want.

I guess what I am asking is how would you write the For i statement
such that it includes everything in the array except the first entry?

Thanks
Helmut Weber - 18 Mar 2005 18:19 GMT
Hi Greg,

For i = LBound(ListArray) + 1 To UBound(ListArray) - 1 Step 3

+ 1 ' !

Could that be all that is to it?

I must be missing the crucial point.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Greg - 18 Mar 2005 18:47 GMT
Helmut,

Through trial and error I found that this will work to exclude the
header words Find and Replace:

For i = 3 To UBound(ListArray) - 1 Step 3
Helmut Weber - 18 Mar 2005 19:03 GMT
Hi Greg,
so it is Lbound + offset
where offset is NumberOfColumns.

By the way, I couldn't find a method to format
a table programmatically with a heading.
Not to speak of repeating headings in case of pagebreaks.

I wonder, what ListArray = WordList.Tables(1).Range.Text
will do in that case.

OT:
An uncle of mine has survived World War II as a submariner.
He's 80 + by now.
Really tough guy.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Greg Maxey - 18 Mar 2005 23:33 GMT
Helmut,

Send an e-mail and we can chat about your uncle.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hi Greg,
> so it is Lbound + offset
[quoted text clipped - 18 lines]
> Word XP, Win 98
> http://word.mvps.org/ 
Helmut Weber - 18 Mar 2005 18:30 GMT
Hi Greg,
I see, hopefully.
That's new stuff to me.
I thought, maybe

>ListArray = WordList.Tables(1).Range.Text
>ListArray = Split(ListArray, Chr(13) & Chr(7))

would create a 2-dimensional array.
But it obviously doesn't.

So the offset would have to be equal to the number
of columns in the table, which is 2.

Or not?

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.