select certain position in document

Q

qa_tester

I wrote macro which suppose to go over table in word document and sum the
existing of specific word.
The problem is that I need to first count the number of tables which the
macro will run on and in the upper part of the document there are tables that
need to be ignor so I want to start the macro from certain position in the
document.

The macro (which is still in progress) is the follwoing:
ub results_2()

' results Macro
' Macro recorded ?31/08/2008 by yonit

Dim Pass_Counter As Integer
Dim Fail_Counter As Integer
Dim mytext As Range
Dim table_count

table_count = ActiveDocument.Tables.Count
For i = 1 To table_count
Set mytext = ActiveDocument.Tables(i).cell(2, 6).Range
mytext.MoveEnd Unit:=wdCharacter, Count:=-1
'MsgBox mytext.Text
If mytext.Text = "pass" Then
Pass_Counter = Pass_Counter + 1
End If
If mytext.Text = "fail" Then
Fail_Counter = Fail_Counter + 1
End If
Next
MsgBox Pass_Counter
MsgBox Fail_Counter
End Sub
 
G

Graham Mayor

If the document or documents that you are processing are constant in
arrangement then you already know the number of tables in the document and
presumably you know the number of the table at which you wish to start
processing, so why calculate it? Simply enter the numbers of the tables eg

Dim Pass_Counter As Long
Dim Fail_Counter As Long
Dim mytext As Range
For i = 2 To 4 Step 2
Set mytext = ActiveDocument.Tables(i).Cell(2, 6).Range
mytext.MoveEnd Unit:=wdCharacter, Count:=-1
'MsgBox mytext.Text
If LCase(mytext.Text) = "pass" Then
Pass_Counter = Pass_Counter + 1
End If
If LCase(mytext.Text) = "fail" Then
Fail_Counter = Fail_Counter + 1
End If
Next i
MsgBox Pass_Counter
MsgBox Fail_Counter

will examine cell 2,6 in tables 2 and 4

It only becomes an issue if there are variable numbers of tables in the
document.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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