Solved

Word Document looping through rows and columns.

Posted on 2014-04-10
2
522 Views
Last Modified: 2014-04-11
Experts, the code below really explains what i want to do. I could use:
For i AS integer = 1 to oTable.columns.count

But I would really prefer to use the for each loop. Is this possible?
Can you show me how to make it work?
Dim oWord AS New Word.Application
Dim oDoc as Word.Document = oWord.Documents.Add
Dim oTable as Word.Table
oWord.range.select
oTable = oDoc.tables.Add(oWord.selection.range, rowCount, columnCount)
For Each orow As Word.Row In oTable.Rows
     For Each oColumn As Word.Column In oTable.Rows(oRow.Index)
          'do column stuff
     Next
Next

Open in new window

0
Comment
Question by:Basicfarmer
2 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
Hi,

pls try

Dim oWord As New Word.Application
Dim oDoc as Word.Document = oWord.Documents.Add
Dim oTable As Word.Table
oWord.Range.Select
oTable = oDoc.Tables.Add(oWord.Selection.Range, RowCount, columnCount)
For Each oRow As Word.Row In oTable.Rows
     For Each oCell As Word.Cell In oRow.Cells
          'do column stuff
     Next
Next

Open in new window

Regards
0
 

Author Closing Comment

by:Basicfarmer
Comment Utility
Ok, I get it now. Great answer as usual...
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

763 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

10 Experts available now in Live!

Get 1:1 Help Now