Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Word 2007 Using a userform to manipulate content controls in a header or footer

271 views
Skip to first unread message

pdb

unread,
Aug 25, 2010, 12:54:17 PM8/25/10
to
Dear all,

Greetings from a grey and wet London.
I am trying to set up a new template in Word 2007. The template will
be used to create a chapter of a report. Another template contains the
Report cover and table of contents which is built using ref fields.
In the chapter template I have some plain text and drop down content
controls in the footer:
Title: Text
Confidential: Dropdown (Select from “Confidential” and “ “ (space))
ReportType: Dropdown (Select from “Select Report Type”, “Report”,
“Discussion Document”, etc)
ClientName: Text
JobNo: Text
What I would like to do is create a userform for users to be able to
manipulate the content controls rather than double-clicking into the
footer. Is this possible?

Thanks in advance.

Jay Freedman

unread,
Aug 25, 2010, 9:27:56 PM8/25/10
to
If you're going to make a userform interface, why bother with content controls at all? They would just duplicate the controls you'll need to have in the userform; and they're a bit difficult to deal
with in VBA.

Instead, in the Click event handler of the userform's OK button, populate a set of document variables with the strings corresponding to the user's choices. Then the footer just needs a corresponding
set of DocVariable fields to display the values.

For sample code, see http://gregmaxey.mvps.org/Create_and_employ_a_UserForm.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

pdb

unread,
Aug 26, 2010, 7:05:30 AM8/26/10
to
On 26 Aug, 02:27, Jay Freedman <jay.freed...@verizon.net> wrote:
> If you're going to make a userform interface, why bother with content controls at all? They would just duplicate the controls you'll need to have in the userform; and they're a bit difficult to deal
> with in VBA.
>
> Instead, in the Click event handler of the userform's OK button, populate a set of document variables with the strings corresponding to the user's choices. Then the footer just needs a corresponding
> set of DocVariable fields to display the values.
>
> For sample code, seehttp://gregmaxey.mvps.org/Create_and_employ_a_UserForm.htm.

>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP        FAQ:http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
>
>
>
> On Wed, 25 Aug 2010 09:54:17 -0700 (PDT), pdb <pduabr...@gmail.com> wrote:
> >Dear all,
>
> >Greetings from a grey and wet London.
> >I am trying to set up a new template in Word 2007. The template will
> >be used to create a chapter of a report. Another template contains the
> >Report cover and table of contents which is built using ref fields.
> >In the chapter template I have some plain text and drop down content
> >controls in the footer:
> >Title: Text
> >Confidential: Dropdown (Select from “Confidential” and “ “ (space))
> >ReportType: Dropdown (Select from “Select Report Type”, “Report”,
> >“Discussion Document”, etc)
> >ClientName: Text
> >JobNo: Text
> >What I would like to do is create a userform for users to be able to
> >manipulate the content controls rather than double-clicking into the
> >footer. Is this possible?
>
> >Thanks in advance.- Hide quoted text -
>
> - Show quoted text -

Jay,
Thanks for your reply. I have used content controls in the Report
cover template and wanted to use a consistent approach. In previous
versions I have used a combination of userforms and bookmarks but find
that users mess up the bookmarks. I was hoping to use content controls
as they are more difficult to screw up and to retain the userform
approach as sometimes the content controls may not be obvious - say
for example a client name in a paragraph of text.
Best Regards,
Preeti

Jay Freedman

unread,
Aug 26, 2010, 9:51:06 PM8/26/10
to
On Thu, 26 Aug 2010 04:05:30 -0700 (PDT), pdb <pdua...@gmail.com> wrote:

>Jay,
>Thanks for your reply. I have used content controls in the Report
>cover template and wanted to use a consistent approach. In previous
>versions I have used a combination of userforms and bookmarks but find
>that users mess up the bookmarks. I was hoping to use content controls
>as they are more difficult to screw up and to retain the userform
>approach as sometimes the content controls may not be obvious - say
>for example a client name in a paragraph of text.
>Best Regards,
>Preeti

Preeti,

I don't see any particular advantage to a "consistent approach" between a cover page and a set of data in a footer. The content controls on the cover page are immediately clickable, while the items in
the footer are not. If I were going to try to be consistent (for whatever reason), I would opt to use DocVariable fields rather than content controls in both places.

The reason I say this is that content controls are difficult to address from VBA. The only item that is guaranteed unique to a given content control is its .ID value; the .Title and .Tag values may be
the same for two or more content controls. The .ID is a random numeric string, which makes it hard to deal with. Because of the possible duplication, you can't use the .Tag or the .Title as an index
into the ContentControls collection. To work with the .Tag as an "index", first you must carefully assign a unique .Tag value to each content control as you create it; then you need a function like
this to locate the control with a specific .Tag so you can assign a string to its range:

Function GetCC(strTag As String) As ContentControl
' find the content control with the specified Tag value
' or return Nothing if there is none
Dim temp As ContentControl

For Each temp In ActiveDocument.ContentControls
If LCase(temp.Tag) = LCase(strTag) Then
Set GetCC = temp
Exit For
End If
Next
End Function

In contrast, the value of a document variable and the DocVariable fields that display it are instantly linked by the name of the variable; you just assign a value to the variable, update the
document's fields, and Bob's your uncle.

DocVariable fields are just as resistant to accidental overwriting as are content controls -- that is, much better than bookmarks. Their only (minor) drawback is that if the document variable hasn't
yet been assigned a value, then updating a DocVariable field that refers to it will cause it to display an error message. That can be avoided by assigning a value, even if just a space character, to
each document variable in the base template.

pdb

unread,
Aug 30, 2010, 11:51:03 AM8/30/10
to
On 27 Aug, 02:51, Jay Freedman <jay.freed...@verizon.net> wrote:

Jay thanks for the explanation - it is appreciated, I think I will
have a closer look at the docvariable fields.
Kind Regards,
Preeti

0 new messages