#1   Report Post  
Bob Inwater
 
Posts: n/a
Default VBA Word to Project

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

  #2   Report Post  
Cindy M -WordMVP-
 
Posts: n/a
Default

Hi ?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 :-)

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Does Word have Keyboard Merges like Word Perfect does? Donnas Mailmerge 1 June 28th 05 09:30 PM
Word2000 letterhead merge BAW Mailmerge 3 June 25th 05 01:17 PM
Underscore (_) will not always display in RTF files (Word 2002). David A Edge Microsoft Word Help 6 June 14th 05 10:39 AM
Envelope Address GR New Users 5 April 24th 05 09:48 PM
Locking Two Words Together to Make a Proper Compound Noun in Word WorkingWoman Microsoft Word Help 2 April 7th 05 02:33 PM


All times are GMT +1. The time now is 10:12 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"