Results 1 to 6 of 6

Thread: Word / ActiveDocumemnt error - object required 424 [***Resolved***]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    Suffolk. UK
    Posts
    162

    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:
    1. 'open word
    2.     Dim Obj As Object
    3.     If Obj Is Nothing Then
    4.         Set Obj = CreateObject("Word.Application")
    5.     Else
    6.         Set Obj = GetObject(, "Word.Application")
    7.     End If
    8.    
    9.     Set Worddoc = Obj.Documents.Add
    10.     Obj.Visible = True
    11.    
    12.     'set up table
    13.  
    14. 'error 424 object requred in the following 2 lines
    15.     ActiveDocument.PageSetup.Orientation = wdOrientLandscape
    16.     ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:=10
    17.  
    18.     'insert headings
    19.     Obj.Selection.typeText Text:=Text1(0).Text & vbCr
    Last edited by Ping; Aug 27th, 2003 at 05:53 AM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    "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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    Suffolk. UK
    Posts
    162
    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:
    1. 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

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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)

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    Suffolk. UK
    Posts
    162
    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

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    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
  •  



Click Here to Expand Forum to Full Width