Solved

Word table array

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
String manipulation in Visual Basic 7 64
passing parameter in sql procedure 9 63
Sorting multiple rows and columns, and count duplicates in Excel 2013 4 80
MsgBox 4 61
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

803 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