Macro for word 2003

C

Chris Lewis

I need to perform the following actions

Search through a document for a string of text.
Then move upwards in the document to find the first paragraph number above
the found text.
Them find that paragraph number in a table at the end of the document
insert an X in the table cell to the right of the cell containing the
paragraph number from above.
Repeat until no more instances of the string are found


I am ok with excel vba but don't know where to start with word.

Thanks in advance for any help you can offer
 
H

Helmut Weber

Hi Chris,
Then move upwards in the document
to find the first paragraph number above
the found text.

hmm...

what do you understand by paragraph number?
Are the paragraphs numbered automatically?
Are they numbered manually, or aren't they numbered at all,
and you just want to find out the index of the
paragraph preceding the found text?

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
C

Chris Lewis

Helmut Weber said:
Hi Chris,


hmm...

what do you understand by paragraph number?
Are the paragraphs numbered automatically?
Are they numbered manually, or aren't they numbered at all,
and you just want to find out the index of the
paragraph preceding the found text?

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Scrub all that above I got most of it working. Its not very elegant but it
works. What I need to know now is if I have a table of rows x. Each row
can contain either 1, 2, 4 or 5 cells. I need to loop through each row in
the table and clear the contents of the Cells 3, 4 and 5 only in the rows
with 5 cells. all other rows are left alone.


so


Selection.Tables(1).Select
j = Selection.Rows.Count
For rownum = 1 To j

Selection.Tables(1).Rows(rownum).Select

If Selection.Cells.Count = 5 Then

Something here to delete the contents of cells 3, 4 and 5 of the current
row#

Next rownum

any ideas?
 
H

Helmut Weber

Hi Chris,

like this:

Sub test9()
Dim r As Long ' Row
Dim c As Long ' cell in row
With Selection.Tables(1)
For r = 1 To .Rows.Count
If .Rows(r).Cells.Count = 5 Then
For c = 3 To 5
.Rows(r).Cells(c).Range.Text = ""
Next
End If
Next
End With
End Sub
--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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