Word Automation from Access - Tables

algecan

Registered User.
Local time
Today, 14:12
Joined
Nov 11, 2009
Messages
37
Hi All,

I have just started to develop a database that will export data directly into a word template. I have used Word automation quite a lot but I'm new to trying to automate Word from Access.

It's going OK at the moment, I have got the db to open up the template, write data and then close. My objective is to add the data to multiple tables within word. So I have created several tables in my word template and then tried to select these tables and write to the them. Everything is thing for the first table but for any other table I get an error message saying that the member of the collection doesn't exit i.e. the table isn't there. I select the table using:

Code:
objWord.selection.tables (2).select

I then used:

Code:
objWord.selection.tables.count

To show how many tables were in the document and it doesn't matter how many there are, it always says there is 1 table.

Can anybody help to explain why it can only see 1 table and what I can do to get around it?

Many thanks.
 
You need to use an object type of document.
Code:
  ...
  Dim obj As Object
  Dim wdDoc As Word.Document
  Set obj = CreateObject("Word.application")
  obj.Visible = True
  Set wdDoc = obj.Documents.Open("YourDocumentNameAndPath.doc")
  'Select table no. 2
  wdDoc.Tables(2).Select
  ....
 
Thanks, just what I needed.
 

Users who are viewing this thread

Back
Top Bottom