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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in creating Word 2003 Table from Acc2003

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
here is my code
Code:
    Set objWord = CreateObject("Word.Application")
   
    'Word Object is created - now let's fill it with data.
    With objWord
   
        .Visible = True
        
        .Documents.Open ("F:\Task Order\ReportTemplates\sample.doc")
        
        .ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:=9, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed

I get an Error on last line
run time error 424
Object required

any ideas
TIA

DougP, MCP, A+
[r2d2] I Built my own R2D2
I love this site and all you folks that helped me over the years!
 
DougP,
I think the [tt]Selection.Range[/tt] is dangling.
Code:
.ActiveDocument.Tables.Add Range:=[b].ActiveDocument.[/b]Selection.Range, _
                           NumRows:=2, _
                           NumColumns:=9, _
                           DefaultTableBehavior:=wdWord9TableBehavior, _
                           AutoFitBehavior:=wdAutoFitFixed

Hope thie helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Now I get different error

run time error 438
Object doesn't support this property or method

Odd
I created a macro in Word to get the code above
and it works if I run it in Word without your additional .ActiveDocument

DougP, MCP, A+
[r2d2] I Built my own R2D2
I love this site and all you folks that helped me over the years!
 
.ActiveDocument.Tables.Add Range:=[highlight].[/highlight]Selection.Range, NumRows:=2, NumColumns:=9, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
thank you PHV
I also had to add a . "Dot" in the table part too
Code:
        With [highlight].[/highlight]Selection.Tables(1)
            If .Style <> "Table Grid" Then
                .Style = "Table Grid"
            End If
            .ApplyStyleHeadingRows = True
            .ApplyStyleLastRow = True
            .ApplyStyleFirstColumn = True
            .ApplyStyleLastColumn = True
            .Cell(1, 1).Range.Text = "Sample #"
            .Cell(2, 1).Range.Text = "1829-001"
            .Cell(3, 1).Range.Text = "1829-002"
            .Cell(4, 1).Range.Text = "1829-003"
        End With
    End With


DougP, MCP, A+
[r2d2] I Built my own R2D2
I love this site and all you folks that helped me over the years!
 
Bottom line, when you automate Word (or Excel or ...) from VBA, ALWAYS use FULL QUALIFIED object references.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top