Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2007

Tip: Looking for answers? Try searching our database.

Word 2007/Visual Basic - Document Branding with Controls

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ryan - 09 Feb 2007 14:02 GMT
Hello,

I'll try to be as specific and short in describing the issue I cannot
resolve or find a work around for as it applies to my company and using word
2007.

I have been assigned the task to find a way to develop one document that
can, based on a button/list box control, set the appropriate images & text in
the document.

In order to do this, I need to find a way to select a paragraph of formatted
text (text that contains bullet properties/font properties, cannot use a
label) and assign it a variable name so that it can have an interaction with
the embedded VB controls in word. It would be most beneficial If i could
somehow anchor this formatted text to a frame, that has access to the
.Visible method in VB, which would make it easy to turn on / off the required
images and text.

Conditional text and hidden text is not an option for the following reasons:

Conditional text is generally a field used for turning off a word, or maybe
a sentence, not a list, table, image etc.

Hidden text works fine for some things, but when im branding 1 document to
be compatible with 3-4 company profiles, hidden text is either "on" or "off"
and i have no way to select which i want to be visible, and which i want to
remain hidden without doing it all at once.

Has anyone tried this before? Someting similar? Suggestions/Solutions?

Thanks,

Ryan
Jay Freedman - 09 Feb 2007 14:56 GMT
Because you've specified Word 2007, you have a solution that's available
only there (or in versions back to Word 2000 using the Compatibility Pack):
Put the paragraph into a Rich Text Content Control. The control can be
named, and you can manipulate each control individually from VBA.

For some good background information, see
http://blogs.msdn.com/microsoft_office_word/archive/tags/content+controls/defaul
t.aspx

(note that the list is in reverse chronological order, so it's best read
from the bottom up).

Signature

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.

> Hello,
>
[quoted text clipped - 31 lines]
>
> Ryan
Ryan - 09 Feb 2007 18:35 GMT
I have considered doing this before, but it also gives me some problems.

Using the Rich Text in the developer panel (to the left of "text") allows me
to insert rich text (that seems to work just like normal text in word) that
gives me access to locking and tagging it. However it does not gives buttons,
drop downs etc access to additional properties such as .Visible, .Value,
.Text etc.

Using the ActiveX Controls menu and inserting Microsoft Rich TextBox
Control, Version 6.0 also generates and error that the program used to create
the control is no longer available. ( I assume it requires Visual basic to be
installed, which is another problem since everyone who will edit certain
parts of this file will not have VB installed).

Any alternatives? (word 2007 or 2003, any version)

> Because you've specified Word 2007, you have a solution that's available
> only there (or in versions back to Word 2000 using the Compatibility Pack):
[quoted text clipped - 41 lines]
> >
> > Ryan
Ryan - 09 Feb 2007 19:02 GMT
Basically to clarify a little more lets try this:

This is a sample document that would feature the functionality I'm looking
for.

<img src="http://www.geocities.com/cs_gfw/1.JPG">

Here we have a list of items in a Rich Text format from the developer menu,
and can still be edited by your normal word user (does not need to code
anything).

I would like to be able to use the button to hide such text similar to this:

<img src="http://www.geocities.com/cs_gfw/2.JPG">

But since this rich text cannot be assigned a NAME, this will not work.

If there is a way to do it, it should yield a result such as:

<img src="http://www.geocities.com/cs_gfw/3.JPG">

- Ryan

> I have considered doing this before, but it also gives me some problems.
>
[quoted text clipped - 57 lines]
> > >
> > > Ryan
Jay Freedman - 10 Feb 2007 04:51 GMT
Content controls do let you manipulate their visibility, text, and so
forth, but the syntax is a bit different from the old controls.

Unless I'm missing something (a good possibility), you can't address a
content control directly by its .Title, .Tag, or .ID property, only by
its index within the document, and that may change as the document is
edited. That means the only reliable way to address a particular
control is to iterate through the collection, checking each one's .Tag
or .ID (the .Title isn't unique, and the .Tag is unique only if you
assign them that way) until you find the one you want.

To toggle a content control's visibility, you can do something like
this:

   Dim cc As ContentControl
   For Each cc In ActiveDocument.ContentControls
       If cc.Tag = "rt1" Then
           cc.Range.Font.Hidden = Not cc.Range.Font.Hidden
           Exit For
       End If
   Next

There is no .Value property; instead you use cc.Range.Text. This is
true for dropdowns and combo boxes just as for text controls.

To change a dropdown's value, you can use something like this:

   Dim cc As ContentControl
   For Each cc In ActiveDocument.ContentControls
       If cc.Type = wdContentControlDropdownList And _
                cc.Tag = "dd1" Then
           cc.DropdownListEntries(3).Select
           Exit For
       End If
   Next

(If you try to access the .DropDownListEntries property for a content
control that isn't a dropdown  or a combo box, you'll get an error.)

I would avoid ActiveX controls like the plague. They're far more
trouble than they're worth. See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnword2k2/html/
odc_activeX.asp

for details of the ones that are available within Word. If you import
VB controls such as the Rich Text Box, you'll need the development
license to be able to put them in, and then you'll have to distribute
the .dll or .ocx that contains them (but other users don't have to
have VB, just the distributed file).

--
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.

>I have considered doing this before, but it also gives me some problems.
>
[quoted text clipped - 57 lines]
>> >
>> > Ryan
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.