create a new table in Word

tadropik

Registered User.
Local time
Yesterday, 18:40
Joined
Jun 24, 2010
Messages
14
Using Access 2007, the following codes produces the following error:
.
Code:
Dim objWord As Object
Set objWord = GetObject("", "word.application")
objWord.Documents.Add
objWord.Visible = True
objWord.ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=2, _
DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed

.
Error:
Run-time error '424'
Object required
.
Note:
it's the objWord.ActiveDocument.Tables.Add statement that's causing the error.
 
Do you have Word open? Your code doesn't have a CreateObject part in there for the word document if there isn't an app open currently.

Personally I would just create a new instance and use it and not worry about an existing instance:

Dim objWord As Object
Set objWord = CreateObject("Word.Application")
 
This is just a guess but I think the issue is with
Selection.Range

because you moved to a late binding method Selection is not valid by itself any more, you might need objWord.ActiveDocument.Selection
 
This is just a guess but I think the issue is with
Selection.Range

because you moved to a late binding method Selection is not valid by itself any more, you might need objWord.ActiveDocument.Selection

That too - Always use things off an instantiated object. Good catch D.
 
WOW. You guys are AWESOME...
.
Changed:
Set objWord = GetObject("", "word.application")
To:
Set objWord = CreateObject("word.application")
.
Changed:
objWord.ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=2, _
DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed
.
To:
objWord.ActiveDocument.Tables.Add Range:=objWord.Selection.Range, NumRows:=1, NumColumns:=2, _
DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed

All is EXCELLENT.

Thank you for all your help.
 

Users who are viewing this thread

Back
Top Bottom