Increment Bookmark name?

Discussion in 'Word VBA Beginners' started by Basalt, Apr 30, 2011.

  1. Basalt

    Basalt Guest

    I have an english and a spanish version of a word form. I have created
    a macro to check the corresponding box in spanish when the english box
    is checked. However, the bookmark name is hardcoded in the macro so
    the macro only works on the first box of each version - checkbox1 and
    checkbox76. Is there a way for me to have the macro increment the
    bookmark name so it correctly marks the checkbox? Such as:

    {checkboxname}
    {checkboxname} + 75

    or some better way?

    Thanks!
    Jason
     
    Basalt, Apr 30, 2011
    #1
    1. Advertisements

  2. Basalt

    Jay Freedman Guest

    On Fri, 29 Apr 2011 16:31:26 -0700 (PDT), Basalt <> wrote:

    >I have an english and a spanish version of a word form. I have created
    >a macro to check the corresponding box in spanish when the english box
    >is checked. However, the bookmark name is hardcoded in the macro so
    >the macro only works on the first box of each version - checkbox1 and
    >checkbox76. Is there a way for me to have the macro increment the
    >bookmark name so it correctly marks the checkbox? Such as:
    >
    >{checkboxname}
    >{checkboxname} + 75
    >
    >or some better way?
    >
    >Thanks!
    >Jason


    You can do something like this:

    For i = 1 To 75
    englishCheckboxName = "checkbox" & i
    spanishCheckboxName = "checkbox" & (i + 75)

    ActiveDocument.FormFields(spanishCheckboxName).Result = _
    ActiveDocument.FormFields(englishCheckboxName).Result
    Next i
     
    Jay Freedman, May 2, 2011
    #2
    1. Advertisements

  3. Basalt

    Basalt Guest

    On May 1, 8:43 pm, Jay Freedman <> wrote:
    > On Fri, 29 Apr 2011 16:31:26 -0700 (PDT), Basalt <> wrote:
    > >I have an english and a spanish version of a word form. I have created
    > >a macro to check the corresponding box in spanish when the english box
    > >is checked. However, the bookmark name is hardcoded in the macro so
    > >the macro only works on the first box of each version - checkbox1 and
    > >checkbox76. Is there a way for me to have the macro increment the
    > >bookmark name so it correctly marks the checkbox? Such as:

    >
    > >{checkboxname}
    > >{checkboxname} + 75

    >
    > >or some better way?

    >
    > >Thanks!
    > >Jason

    >
    > You can do something like this:
    >
    > For i = 1 To 75
    >    englishCheckboxName = "checkbox" & i
    >    spanishCheckboxName = "checkbox" & (i + 75)
    >
    >    ActiveDocument.FormFields(spanishCheckboxName).Result = _
    >       ActiveDocument.FormFields(englishCheckboxName).Result
    > Next i


    Thanks!
     
    Basalt, May 2, 2011
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.