Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Word table array

Posted on 2002-04-22
5
384 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

837 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