PDA

View Full Version : how to update specific fields



Clarksonjj
12-21-2016, 06:10 AM
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.

gmaxey
12-21-2016, 06:38 AM
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

Clarksonjj
12-22-2016, 03:56 AM
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.

gmaxey
12-22-2016, 04:41 AM
There should be no bookmark. Either map the like titled controls http://gregmaxey.com/word_tip_pages/content_control_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