Consulting

Results 1 to 4 of 4

Thread: how to update specific fields

  1. #1

    how to update specific fields

    Hi all, i know nuts bout vba and really need some guidance here.

    Im doing some repetitive input in a words which consist of few letters which is require on monthly basis. Layout is pretty much fixed, i just need to amend the informations throughout the whole letter which can be 8 pages.

    And so i googled around and have a simple fix which is to create a bookmark and insert a field which will ask for the content. After which, I make a field to reference to that particular bookmark. (Show below)

    Bookmark < {ASK Name “Name” \* MERGEFORMAT} >
    Field {REF NAME \*MERGEFORMAT}

    Then I create a command button to execute "fields.update" and copy&paste the field within the letter and repeat this whole process for the rest of the informations.( i have about 10 sets of repetitive informations to fill within the pages.

    This solved my issue of repetitive laborious input which can be done at one time. However, the problem is i might have only 5 set of information at the initial stage and rest of the information will come later. I would like to create 2 command buttons to update each set of 5 fields.

    Appreciate if anyone can guide me on this.

    Thank in advance.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,338
    Location
    What version of Word are you using? Anything above 2007 and I would consider your method like accelerating a Ferrari with a horsewhip.

    Put titled content controls where you have the bookmarks:

    Sub Set1()
      With ActiveDocument
        .SelectContentControlsByTitle("Name").Item(1).Range.Text = InputBox("Name?")
        .SelectContentControlsByTitle("Name2").Item(1).Range.Text = InputBox("Name2?")
        '....
      End With
    lbl_Exit:
      Exit Sub
    End Sub
    Sub Set2()
      With ActiveDocument
        .SelectContentControlsByTitle("Name6").Item(1).Range.Text = InputBox("Name6?")
        .SelectContentControlsByTitle("Name7").Item(1).Range.Text = InputBox("Name7?")
        '....
      End With
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Hi Greg,

    Afraid you are right on this. im using 2010.

    Your method solved the segregation of information but my fields that make reference to the bookmark does not get updated.

    i have also tried to do multiple titled content controls of the same title but only one will get update.

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,338
    Location
    There should be no bookmark. Either map the like titled controls http://gregmaxey.com/word_tip_pages/...rol_tools.html
    or use
     With ActiveDocument 
            .SelectContentControlsByTitle("Name").Item(1).Range.Text = InputBox("Name?") 
    .SelectContentControlsByTitle("Name").Item(2).Range.Text = InputBox("Name?") 
    .SelectContentControlsByTitle("Name").Item(3).Range.Text = InputBox("Name?") 
    .SelectContentControlsByTitle("Name").Item(4).Range.Text = InputBox("Name?") 'etc. 
            .SelectContentControlsByTitle("Name2").Item(1).Range.Text = InputBox("Name2?") 
             '....
        End With
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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