Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Table to word

Status
Not open for further replies.

eagleclaw

Programmer
Sep 20, 2002
19
US
I am trying to add a table to a word document from access and keep getting the dreaded "Object Required" at wordapp.ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=5
OK so I may be the only one that dreads it.

Dim dbs As Database
Dim wordapp As Object
Dim rst As Recordset
Dim strDocPath As String

strDocPath = "F:\Secy-SD\ServiceList\MonthlyReport.Doc"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("QuarterlyClientInfoQuery")

rst.MoveLast
rst.MoveFirst
Set wordapp = CreateObject("Word.Application")
With wordapp
.Visible = True
.Documents.Open (strDocPath)
End With

wordapp.ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=5
With Selection.Tables(1)
If .Style <> &quot;Table Grid&quot; Then
.Style = &quot;Table Grid&quot;
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
End With

'Put Column Titles in First Row
'Add New Table
'Do While rst.EOF = False

'Concantenate Data
'Insert Data into Cell
'Move To Next Cell
'Move To Next Row
 
First, make sure you have a reference to Microsoft Word 9.0 Object Library in your references. Do ATL+F11, click on Tools, References. If not, check the highest version of the library you have and move it near the top.

Otherwise you can try this:

Dim appWord As Word.Application
On Error Resume Next
AppActivate &quot;Microsoft Word&quot;
If Err Then
Shell &quot;c:\Program Files\Microsoft Office\Office\&quot; _
& &quot;Winword /Automation&quot;, vbMaximizedFocus
End If
On Error GoTo 0

The &quot;Shell&quot; will definitely turn on Word.

Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top