+ Reply to Thread
Results 1 to 9 of 9

Word Table of Contents from Excel

  1. #1
    Registered User
    Join Date
    08-01-2010
    Location
    Swindon, Wiltshire
    MS-Off Ver
    Excel 2003
    Posts
    30

    Thumbs up Word Table of Contents from Excel

    I am creating an Excel application to write out a Word document based on the contents of various cells. No problem with creating the document and writing the text. But, I'm stuck on creating the table of contents. This code generates the error "Wrong number of arguments or invalid property assignment" but I can't work out what is wrong. Any ideas?
    Please Login or Register  to view this content.
    Last edited by BillWilts; 11-11-2010 at 04:49 AM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Word Table of Contents from Excel

    This will do the trick:

    Please Login or Register  to view this content.



  3. #3
    Registered User
    Join Date
    08-01-2010
    Location
    Swindon, Wiltshire
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Word Table of Contents from Excel

    Thanks for the reply. Unfortunately I'm still getting the same error!! It might be because I have references to objects mixed up but in spite of experimenting I'm still no further forward. This is my current piece of code:
    Please Login or Register  to view this content.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Word Table of Contents from Excel

    Be very careful where to place code that supposes a with statement.
    You can't add a table of contents to a selection.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-01-2010
    Location
    Swindon, Wiltshire
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Word Table of Contents from Excel

    After much frustrating trial and error I still can't get it to work. The problem seems to be in addressing the ActiveDocument. This piece of code works in a Word document (slightly modified) but not from Excel. Any further thoughts?

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Word Table of Contents from Excel

    Your statement isn't correct.
    You'd better not use trial and error, but analyse the code instructionwise. If you know what the code does and why you can effectively adapt it to your wishes.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-01-2010
    Location
    Swindon, Wiltshire
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Word Table of Contents from Excel

    Thanks for your response. I have incorporated that piece of code into the routine that creates the Word document which now works as intended.

  8. #8
    Registered User
    Join Date
    04-07-2014
    Location
    ch
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Word Table of Contents from Excel

    hello i have the same problem , is possible to you to show the function me the function?

  9. #9
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Word Table of Contents from Excel

    tugaluis,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1