VBA Word to Project

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to read data from a Word Table with VBA that is written in
MSProject. One would think that the object library would be the same but…..
So the below code works like a charm when it is run as a Word Macro but under
MSProject I can not seem to find the tables in the Word Doc.

******************This is the code that works in Word****************
Sub RetrieveTableItems()
On Error GoTo ErrorHandler
i = 1

' Loop through each row in the table.
For Each oRow In ActiveDocument.Tables(8).Rows 'Index # finds the Table
in question
C = 0
For Each oCell In oRow.Cells ' Loop through each cell in the
current row.
If C = 0 Then
ColOne(i) = oCell.Range
ElseIf C = 1 Then
ColTwo(i) = oCell.Range
ElseIf C = 2 Then
ColThree(i) = oCell.Range
ElseIf C = 3 Then
ColFour(i) = oCell.Range
ElseIf C = 4 Then
ColFive(i) = oCell.Range
ElseIf C = 5 Then
ColSix(i) = oCell.Range

End If

C = C + 1
Next oCell
C = 7
i = i + 1

Next oRow


End Sub

************this is almost the same code but can not see the
table**************

Sub ReadWordTables()
Dim CurrentTable As Word.Table
Set WordApp = Word.Application
Set myDoc = Word.ActiveDocument

WordApp.Activate
WordApp.Visible = True
myDoc.Activate
Set CurrentTable = myDoc.Tables(1)

On Error GoTo ErrorHandler
i = 1

' Loop through each row in the table.
For Each oRow In CurrentTable 'Index # finds the Table in question
C = 0
For Each oCell In oRow.Cells ' Loop through each cell in the
current row.
If C = 0 Then
ColOne(i) = oCell.Range
ElseIf C = 1 Then
ColTwo(i) = oCell.Range
ElseIf C = 2 Then
ColThree(i) = oCell.Range
ElseIf C = 3 Then
ColFour(i) = oCell.Range
ElseIf C = 4 Then
ColFive(i) = oCell.Range
ElseIf C = 5 Then
ColSix(i) = oCell.Range

End If

C = C + 1
Next oCell
C = 7
i = i + 1

Next oRow




End If


End Sub
 
Hi =?Utf-8?B?Qm9iIElud2F0ZXI=?=,
I am trying to read data from a Word Table with VBA that is written in
MSProject. One would think that the object library would be the same but…..
So the below code works like a charm when it is run as a Word Macro but under
MSProject I can not seem to find the tables in the Word Doc.
Just a hint for future problems: this is an end-user group (which would have
been obvious if you'd read a few messages, first). VBA questions will probably
get a quicker response in one of the word.vba groups.

As to your problem

1. Are you getting any error messages. "Doesn't work" isn't very descriptive,
nor help us to track the problem down.

2. Are you aware of how to set up a "link" to an outside application through a
COM interface? Using CreateObject, GetObject or the New keyword? If none of
those rings any bells with you, look them up in the general VB Help in any
Office application.

3. You also need to activate a reference to the appropriate Word library
(Tools/References)

Do all that, and then show me the code you've worked out to pick up a
Word.Application object. Then I can show you how to incorporate that into the
code you've got. If you're totally perplexed, there's an example for automating
Word from within Excel on the word.mvps.org site that should give you the
necessary framework.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
 
Back
Top