Solved

Word table array

Posted on 2002-04-22
5
371 Views
Last Modified: 2007-12-19
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
Comment
Question by:allenpitts
  • 2
  • 2
5 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 6961576
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
 
LVL 1

Accepted Solution

by:
alfanhendro earned 200 total points
ID: 6961891
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
 

Author Comment

by:allenpitts
ID: 6963032
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
 
LVL 44

Expert Comment

by:bruintje
ID: 6963202
what was wrong with my answer?
0
 

Author Comment

by:allenpitts
ID: 6963400
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now