How do you use VBA (Word) to add to an existing multilevel list?

Anonymous
2023-01-06T10:48:14+00:00

Hi

I am trying to use VBA (Word) to add to an existing multilevel list (it is for a document for a method with changing variables)

A few points about what I'm trying to add (I don't know if they are relevant but I want to cover everything):

It is a 'DOCPROPERTY' field which may or may not have text depending on a checkbox in a user form

It may be at the end or the middle of the list (if it's in the middle it will have to change the numbers of the points after)

It needs to start the level before the previous point for example:

  1. Hello a. World
       i. HELLO World
    
       ii. HELLO WOLD
    
    b. New text to add
  2. Bye World

I have tried making the field a bookmark, then using this code (below) to make it part of the list

thisdocument.Bookmarks("BOOKMARK1").ListFormat.ApplyNumberDefault

or

thisdocument.Bookmarks("BOOKMARK1").ListFormat.ApplyOutlineNumberDefault

(in accordance with: Selection.Range.ListFormat.ApplyNumberDefault in: https://learn.microsoft.com/en-us/office/vba/api/word.listformat)

But an error comes up:

'Compile error:

Method or data member not found'

and the '.ListFormat' part of the code was highlight

I'm open to other ways of doing as I am still new to VBA

Kind regards,

Dan

Microsoft 365 and Office | Word | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Charles Kenyon 160K Reputation points Volunteer Moderator
    2023-01-06T15:46:19+00:00

    To clarify, a DOCPROPERTY field, not a Document Property Content Control?

    Your template should be set up with a multilevel list that has its levels attached to discrete paragraph styles. (more below)

    If you have done this, to make a paragraph a given level, you simply format it using the appropriate style.

    If you use automatic paragraph numbering or bullets read Shauna Kelly's directions on numbering and bullets. Start with How to create numbered headings or outline numbering in Word 2007 and Word 2010. For large documents you must follow these directions or you will lose your hair!
    (Mac version: https://www.brandwares.com/bestpractices/2016/06/outline-numbering-in-word-for-os-x/)

    This may seem a bit convoluted at first, but it really is not. Just follow the steps. Shauna Kelly's instructions use the built-in heading styles, but you can use any existing paragraph styles including your custom styles. There are, however advantages to using the built-in heading styles when you create a Table of Contents. Here are some more advantages: Why Use Word's Built-In Heading Styles? by Shauna Kelly Note, you can modify these built-in styles to look exactly the way you want.

    If you want, I can provide links to videos demonstrating setting up numbering linked to styles.

    The basic idea is that the numbering is set using the Define MultiLevel List dialog with each numbering level being attached to an existing paragraph style. Once you have this set up, you should not use the buttons for numbering in the Ribbon but rather apply the appropriate style for that level.

    You can save a document with this as a template for future documents if you want so you will not need to do this every time.

    1 person found this answer helpful.
    0 comments No comments
  2. Paul Edstein 82,826 Reputation points Volunteer Moderator
    2023-01-07T00:24:03+00:00
    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2023-01-09T09:03:21+00:00

    I'm not sure what the difference is between a DOCPROPERTY field and a Document Property Content Control, however I created the field by:

    Creating a Custom Document Property in Properties> Advanced Properties>custom, then added the field using insert>field>DocProperty> CustomNewTextToAddField, then put a bookmark around the field, the field is changed based on a check box in a user form using the following code:

    If NewTextToAddCheckbox.Value = True Then

    ThisDocument.CustomDocumentProperties("CustomNewTextToAddField").Value = "New text to add"

    end if

    I hope this clarifies more what I did

    0 comments No comments
  4. Stefan Blom 325K Reputation points MVP Volunteer Moderator
    2023-01-09T09:19:13+00:00

    In general, mapped content controls are a special type of controls in the sense that if you insert one and the same control in multiple locations, you can change the content for one occurrence and Word will update the other occurrences.

    The document properties at Insert > Quick Parts > Document Property are built-in mapped content controls.

    1 person found this answer helpful.
    0 comments No comments
  5. Anonymous
    2023-01-09T10:00:31+00:00

    thank you, I have come across these before, but found they were to general for what I need them for.

    0 comments No comments