|
-
Aug 27th, 2003, 05:09 AM
#1
Thread Starter
Addicted Member
Word / ActiveDocumemnt error - object required 424 [***Resolved***]
Ok, im having problems with the ActiveDocuments in the following code, and its my first time using word, any pointers where im going wrong, im sure its something simple, but just cant get there????
do i need to declare the ActiveDocument or a DoEvents??
thanks
.....
VB Code:
'open word
Dim Obj As Object
If Obj Is Nothing Then
Set Obj = CreateObject("Word.Application")
Else
Set Obj = GetObject(, "Word.Application")
End If
Set Worddoc = Obj.Documents.Add
Obj.Visible = True
'set up table
'error 424 object requred in the following 2 lines
ActiveDocument.PageSetup.Orientation = wdOrientLandscape
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:=10
'insert headings
Obj.Selection.typeText Text:=Text1(0).Text & vbCr
Last edited by Ping; Aug 27th, 2003 at 05:53 AM.
-
Aug 27th, 2003, 05:22 AM
#2
"ActiveDocument" is an object within Word, so you need to preceed it with the Word object (in this case Obj)
eg:
Obj.ActiveDocument.PageSetup.Orientation = wdOrientLandscape
BUT.. I would recommend using your document object (Worddoc) rather than ActiveDocument, as you can't guarantee that the document you have loaded will be the active one (the user might open another document while your code is running).
eg:
Worddoc.PageSetup.Orientation = wdOrientLandscape
-
Aug 27th, 2003, 05:36 AM
#3
Thread Starter
Addicted Member
Thanks Si,
I tried that, but no joy??????
Form file corrupted a few days ago, and i had to rebuild it from a backup....(vb crashed during a save) it all works fine excpet these 2 line, i was using
VB Code:
Worddoc.PageSetup.Orientation = wdOrientLandscape
origionally, but thats givin me the same error too?
I cant seem to see that this sub has any dependance on any other and should be working.... ive tested it on a new blank form and it doesnt work there either.
Any ideas?
thanks fofr the post btw
-
Aug 27th, 2003, 05:45 AM
#4
It works fine for me, here's the code I had for the two lines:
Worddoc.PageSetup.Orientation = wdOrientLandscape
Worddoc.Tables.Add Range:=Obj.Selection.Range, NumRows:=2, NumColumns:=10
have you got a project reference to "Word Object Library"?
if not, you need to use the value for wdOrientLandscape rather than the constant. The value of wdOrientLandscape is 1, so that would become:
Worddoc.PageSetup.Orientation = 1 '(wdOrientLandscape)
-
Aug 27th, 2003, 05:52 AM
#5
Thread Starter
Addicted Member
Ahhhhh there lays the problem... I dont, i removed it between the backup, and now...as i dont know what version of word users will have, but the revised line worked a treat.
So is there a ref or help guide anywhere if im not using the word obj lib to get my tables working..
Thanks for putting a smile on my face
-
Aug 27th, 2003, 05:58 AM
#6
No worries mate 
What I tend to do is use the object library while I am getting all the functionality working (to get the context sensitive help + lists of object properties/methods), then remove the library afterwards.
If you do that you need to declare the variables differently while you have the library (eg: Dim Worddoc As Word.Document )
And don't forget, Word is great at writing the code for you - just record a macro and copy the code (with minor modifications like I mentioned above)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|