• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

Word table array

Hello Experts,

I have a Word doc with a table in it. I am trying to traverse the doc and write the data in the table, which is seven columns wide to an array. The data (can I attach a doc?) I need is preceded by the words Launch Packages in Progress and proceded by the words Mailed Launch Packages. I have created a macro in Word which finds the words Launch Packages in Progress and begins writing the
data from the table until it reaches the string Mailed Launch Packages or the end of file. For some reason I am getting a COmpile Error Loop without Do. I don't understand this. What is the problem?
Thanks.

Sub ALPS4()
'
' ALPS4 Macro
' Macro recorded 04/22/02 by Allen Carr Pitts
'
Dim array1(500, 7) As String
Dim counter As Integer
Dim LineCount As Integer
Dim SecondCount As Integer

    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "Launch Packages in Progress"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.HomeKey Unit:=wdLine
    Selection.MoveDown Unit:=wdLine, Count:=1

    Do Until EOF(1)
        'move down one line
        Selection.MoveDown Unit:=wdLine, Count:=1
       
        'skip line if mailing text header found
        If Selection.Text = "Mailed Launch Packages" Then
            Loop
        End If
               
        'increment line counter
        LineCount = LineCount + 1
               
        For counter = 1 To 7
            array1(LineCount, counter) = Selection.Text
            Selection.MoveRight Unit:=wdCell
        Next counter
    Loop
   
    Debug.Print array1(1, 1)

End Sub

0
allenpitts
Asked:
allenpitts
  • 2
  • 2
1 Solution
 
bruintjeCommented:
Hi Allenpits,

Do Until EOF(1)
   'move down one line
   Selection.MoveDown Unit:=wdLine, Count:=1
       
   'skip line if mailing text header found
   if Selection.Text <> "Mailed Launch Packages" Then
               
     'increment line counter
     LineCount = LineCount + 1
             
     For counter = 1 To 7
       array1(LineCount, counter) = Selection.Text
       Selection.MoveRight Unit:=wdCell
     Next counter
   end if
Loop

change you check statement to [if <> then] instead of [if then loop]

the second use of loop was without a Do

HTH:O)Bruintje
0
 
alfanhendroCommented:
A bit addition,

Remember to always enclose your control statement properly.

For.. Next
If..Endif
Do While...Loop


For example, you cannot do something like this:

  If
    For
    'missing Next here
  End If
    Next 'where this Next come from, where is the For?

In this case, you get error "Next Without For", or "For Without Next", because the compiler will look for the matching of "For", that is a "Next" inside the If block (If...End If).
So follow the order. See this.
Begin is used in place of the opening keywords,
e.g. If, Do While, For
End is used in place of the closing keywords,
e.g EndIf, Loop, Next

Begin#1
  ...
  Begin#2
     ...
     Begin#3
         ...
     End#3
     ...
  End#2
  ...
  Begin#4
     ...
  End#4
  ...
End#1

Hope it helps. Regards
0
 
allenpittsAuthor Commented:
Good morning Alfahendro,

Thanks for yor excellent answer. I believe the point you are making has to do with nesting. We have a similar problem in web pages opening and closing tags. HTML will accept improper nesting but XML will not.

If I may ask one more brief and specific question.
I ran my code and I got Run time error 52 Bad file name or number. The debugger pointed to the line of code:   Do Until EOF(1).

The MS knowldge base says  
Bad file name or number (Error 52)
A statement refers to a file with a file number or file name that is:
An invalid name or number
Not specified in the Open statement
Specified in an Open statement, but has since been closed
Out of the range of file numbers (1-511)

The file name was not specified in the Open statement because there was no Open statement in the code. After research I inserted
Open "AgreementLaunchPackageStatus020322b.doc" For Input AS #1

I now get Run-time error 4605 This method or property is not available because some or all of the object does not refer to a table.

Can you tell what is causing this?

Thanks.

Revised code

Sub ALPS5()
'
' ALPS5 Macro
' Macro created 04/23/02 by Allen Carr Pitts
'
'
Dim array1(500, 7) As String
Dim counter As Integer
Dim LineCount As Integer
Dim SecondCount As Integer

    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "Launch Packages in Progress"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.HomeKey Unit:=wdLine
    Selection.MoveDown Unit:=wdLine, Count:=1

Open "AgreementLaunchPackageStatus020322b.doc" For Input As #1

   Do Until EOF(1)
  'move down one line
  Selection.MoveDown Unit:=wdLine, Count:=1
     
  'skip line if mailing text header found
  If Selection.Text <> "Mailed Launch Packages" Then
             
    'increment line counter
    LineCount = LineCount + 1
             
    For counter = 1 To 7
      array1(LineCount, counter) = Selection.Text
      Selection.MoveRight Unit:=wdCell
    Next counter
  End If
Loop

   
    Debug.Print array1(1, 1)

End Sub



PS I would be willing to pay up to $30 for a solution to this macro. I would need an email so I can send you the Word 97 document. Email if interested apitts@novationco.com

 
0
 
bruintjeCommented:
what was wrong with my answer?
0
 
allenpittsAuthor Commented:
Hello,

There was nothing wrong with your answer. I used your code and it soved the loop problem. I thought I credited you 200 points. Did you not get it? If you did not parhaps we can arrange some way tro make the exchange.

Thanks.

Allen

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now