As far as the content controls side of this is concerned...
You are absolutely right that there is little obvious documentation on how
to use content controls. There is stuff out there on the web, but as far as
I know you cannot make them work the way they are supposed to work without
setting them up with some code (which can be VBA). It's all Word 2007-only.
The idea is that the data in a content control is like a "window" that
displays the value of a piece of data held in an area of the Word document
called the data store. The data store has bits of data defined using XML.
Each content control has an associated piece of XPATH code which tells it
which data in the data store to display. Whenever Word changes the data in
the data store, the values of content controls "connected" to that data
should be updated automatically.
For example, create a dropdown content control, and a plain text content
control, in your document. Using the Properties button in Word's developer
tab, create some rows for the dropdown and give it the title myvalue. Give
the plain text content control the title myvalue as well. It may be useful
to ensure that the controls cannot be deleted.
Copy the following VBA into the VBA editor and run SetUpCustomXMLPart. Click
the "Design Mode" button in Word so that the controls are in their "runtime"
rather than their "design time" state, then try selecting different items in
the dropdown. The results should be reflected in the plain text content
control.
Beyond that, you're on your own if you want to go down this route. The only
thing I would say is that in simple cases such as this, you do not need VBA
to use the form, just to set up the controls so that they reference the data
store correctly. And you may need to ensure that the document is /not/ in
design mode before you use it.
Peter Jamieson
Sub SetUpCustomXMLPart()
Dim objCustomXMLPart As Office.CustomXMLPart
Dim rngStory As Word.Range
Dim objContentControl As Word.ContentControl
Dim objContentControls As Word.ContentControls
Call DeleteAllCustomXMLParts
Set objCustomXMLPart = ActiveDocument.CustomXMLParts.Add
LoadMyCustomXML objCustomXMLPart
' This assumes that the content controls are in the main document body
For Each objContentControl In ActiveDocument.ContentControls
' set all controls with title myvalue to point to the same value in the data
store
If objContentControl.Title = "myvalue" Then
objContentControl.XMLMapping.SetMapping "ns0:mydata/ns0:mydropdownvalue"
End If
Next
Set objCustomXMLPart = Nothing
End Sub
Sub LoadMyCustomXML(myCustomXMLPart As CustomXMLPart)
Dim strXML As String
Const S = vbCrLf
' Define a simple XML value called mydropdownvalue
strXML = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" & S
strXML = strXML & "<mydata
xmlns='
http://www.pjmsn.me.uk/xmlschemas/mydata'>" & S
strXML = strXML & "<mydropdownvalue/>" & S
strXML = strXML & "</mydata>"
myCustomXMLPart.LoadXML strXML
End Sub
Sub DeleteAllCustomXMLParts()
Dim oCustomXMLPart As Office.CustomXMLPart
For Each oCustomXMLPart In ActiveDocument.CustomXMLParts
If Not oCustomXMLPart.BuiltIn Then
oCustomXMLPart.Delete
End If
Next
End Sub
oldstonebuddha said:
I have been using the content control. How would I refer to a dropdown (or
combobox) content control value (and have it update automatically)? There
is
very little information in the help files on content controls. As I
stated
earlier, I can do so by pasting an HTML link, but I have to use code to
get
it to update the link when a user changes the value.
Thanks for all your help.
--
macropod said:
Hi,
Are you using a Content Control 'Drop Down List', or a Dropdown
formfield? I've been referring to the latter (available in Word
2007's Controls under 'Legacy Tools', whereas I now suspect you're
referring to the former. Dropdown formfields have both a bookmark
value and a 'calculate on exit' option that allows them to update all
cross-references without the need for a macro. The formfields
available under the 'Legacy Tools' are also compatible with earlier Word
versions - Content Controls are not.
--
Cheers
macropod
[MVP - Microsoft Word]
message
I don't see any "internal bookmark" or any way to insert one. I was
able to
copy the contents and "paste special" "paste HTML link. That seemed to
work.
To get it to auto-update, I had to go into VB and put a "fields.update"
command into the ContentControlOnExit subroutiene:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As
ContentControl, Cancel As Boolean)
Fields.Update
End Sub
Is there a more elegant way to do this...espicially without using a VB
code?
Why can't I refrence the content control's value directly? It's a pain
getting a digital signature on the project and configuring end-users
options
so they don't have to mess with the macro security every time.
Regards
:
Hi,
If you're getting a duplicate of your dropdown field, that suggests
you've bookmarked the dropdown field and you're using that
bookmark instead of the dropdown field's internal bookmark. Don't do
that - use the dropdown field's internal bookmark instead.
To
access the dropdown field's internal bookmark, select the field,
right-click and choose 'properties'. There you can insert a
bookmark name (or use whatever's already there). Then delete the other
bookmark from your dropdown field and use just the
internal
one.
--
Cheers
macropod
[MVP - Microsoft Word]
message
Hmmm, I was actually using a formula field. I tried the ref field
as you
indicated below, and that actually inserts a copy of the dropdown,
rather
than the value of the dropdown.
All I want to do is insert the string value selected in the dropdown
later
in the document...and have it update as it changes. I'm suprised it
is so
difficult to do so. This is simplicity in excel, access, vb...but
apparenty
not so much in word.
:
Hi,
I suspect you're referencing the dropdown field with a field coded
something like:
{REF Dropdown1 \# 0;0} or {Dropdown1 \# 0;0}
What this *actually* returns is '-30', but the ';0' in the picture
switch is forcing it to show as an absolute value. If you
had
a
field coded something like:
{REF Dropdown1 \# 0} or {Dropdown1 \# 0}
you'd see '-30'.
To get the REF field to show your text, as well as the number,
delete the picture switch. That is, use a field coded something
like:
{REF Dropdown1} or {Dropdown1}
--
Cheers
macropod
[MVP - Microsoft Word]
in message
Hello,
I am working on creating a contract in Word 2007 in which I want
to lock
down most of the document, and then limit certain terms to a
predefined
range. As an example, I would like the document end-user to be
able to
select billing terms of either:
"thirty (30)" days; or
"sixty (60)" days
So I inserted a dropdown with those choices. I would like their
selection
to update text later in the document. So I assigned the dropdown
a bookmark
and then inserted a formula field referencing the bookmark. This
works,
however it only shows the text in parenthesis (i.e. it shows
"(30)" not
"thirty (30)". What is going on? Is there a better way to
accomplish this?
Thanks in advance for your help.
Regards