How to create a window showing building block organiser in 2007

P

Peter

Ideally I would like the window to be formated similiat to the autotext entry
in Word 2003 e.g. shows the list of names of the items then a preview of the
contents of the item. Ideally it would be a modeless window that could float
over the application but this is not necessary. The basic context is that I
use Word Autotext enties to insert comments into documents when making
assignments.

It works very well in Word 2003 (the autotext box allows you to easily key
through the enteries and the preview that is shown is large enough to read
the entries) but in 2007 it is not as easy to use (the names are not shown in
a list and the entries are not large enough to read). About 13 minutes into
the screeen movie at http://baker-evans.com/marker's-assistant/demo.html
there is a demo.

Any assistance woudl be gratefully received,
Pete Evans
 
D

Doug Robbins - Word MVP

You could use a UserForm, displayed as modeless, that contains a combobox, a
multiline textbox and a command button named cmbAutotext, txtAutotextValue
and cmdInsertComment respectively and have the following code in the User
Form

Private Sub cmbAutotext_Change()
With Me.cmbAutotext
.BoundColumn = 2
Me.txtAutotextValue.Text = .Value
End With
End Sub

Private Sub cmdInsertComment_Click()
ActiveDocument.Comments.Add Range:=Selection.Range,
Text:=txtAutotextValue.Text
End Sub

Private Sub UserForm_Initialize()
For i = 1 To NormalTemplate.AutoTextEntries.Count
With NormalTemplate.AutoTextEntries(i)
Me.cmbAutotext.AddItem .Name
Me.cmbAutotext.List(Me.cmbAutotext.ListCount - 1, 1) = .Value
End With
Next i
End Sub

The Initialize statement will load the combobox with the names of the
autotext entries, when an entry is selected in the Combobox, its value will
be displayed in the textbox and clicking on the command button will insert a
comment containing the selected autotext at the location of the selection.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

Peter

Doug,

Thanks for your quick reply ... and I notice that you live just down the
range.

Unfortunately it has been soooo long since I did any VBA that it would take
a while for my fingers to create a UserForm and the various buttons and
fields. Would you have an example that you could send me to at least get me
started -- I can at least see what the code is doing. Will the text box that
displays the entries show the text be large enough to read or will it attempt
to do a page preview as the built in Building Block Organiser attempts to do.

Again, thanks for your help so far,
Peter Evans
 
G

Greg Maxey

How long could it really take to create 1 field, 1 combobox, and 1 command
button? ;-)

You might be interested in
http://gregmaxey.mvps.org/Proofreader_Marks_AddIn.htm . It could easily be
adapted to include a supertip that included the text of the comment.
Supertips show when you mouse over the menu control.

While it would take considerable work to set up initially, you might also
employ a gallery control that shows actuall images of your intended comment
or marking.

See the Signature Gallery here:
http://gregmaxey.mvps.org/Ribbon_Gallery_Control.htm
 
G

Greg Maxey

Peter,

I went ahead and added the code to include supertip text to the dropdown
controls. The supertip text is the same as the predefined comment text that
appears in the userform. One thing that I like about this method is it give
you a chance to quick edit your comment before inserting it.

Please bear in mind that Proofreader Add-In is not a commerial product and
has not be extensively tested. It is simply the child of my efforts to
provide a working example of a dynamic dropdown control in the ribbon on my
website.
 
D

Doug Robbins - Word MVP

As I have give you the code, I would suggest that it would take a lot less
time than getting to the point of the movie to which you referred.

I would suggest however that thinking about it now, the form would be easier
to use if it used a Listbox rather than a Combobox.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

jec

That's interesting Doug and Greg, MVP Christian Freßdorf says that Building
Blocks cannot be previewed in a modeless userform in Word 2007.
 
J

Jay Freedman

Hi Pete,

Christian is right that the preview from the Building Blocks Organizer isn't
available in VBA/userforms, but what Doug has written doesn't display a
"preview". It displays the text of the entry, in the font used for the multiline
text box in the userform. It won't show any formatting that's included in the
entry; and if the entry contains a graphic or a field, you'll see an asterisk or
the field code, respectively. On the plus side, if the entries are all text, the
display is guaranteed to be readable.

Greg's contribution doesn't attempt to display anything except the name of the
entry (and a tooltip with an explanatory phrase) -- no preview there, either.

Programmatic access to the Building Block preview control is something we're
discussing with Microsoft as a desirable feature for the next version, but it's
not something to count on, and definitely not available now. And if it does
become available, it'll probably be the same tiny unreadable picture you've
already said you didn't like.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
G

Greg Maxey

Jay, Doug, Peter, jec,

I have been toying with this issue for a few hours and another option is to
use one of the custom building block galleries. The display in the gallery
control is larger (not by much) and usually readable as compared to the full
page preview in the organizer.

I have put together a Web tips page describing how the method can be
deployed:

http://gregmaxey.mvps.org/Buiild_Employ_Custom_BB_Gallery.htm
 
J

jec

Sorry Greg,
Content Control (CC) with a Building Blocks Category list works very well in
custom templates, as does having the Gallery on the ribbon showing the
Gallery also.
 
P

Peter

Gary,

You are right, it was not that difficult once I had some time to sit down
and look at it.

I now have the UserForm, displayed as modeless, that contains a listbox, a
multiline textbox and a command button named
cmbAutotext, txtAutotextValue and cmdInsertComment respectively and the code
you provided.

I scroll through the listbox or use the arrow keys and the text of the
highlighted autotext item is displayed in the textbox all in a modeless
UserForm.

The question is that I like the list box to automatically scroll if the user
clicks it then starts to type characters e.g. if the autotext names are fred,
jane, joan and sue then the user typed J then Jane would be highlighted and
as soon as they pressed O then joan would be highlighted.

How do I get this type of behaviour?

As you probably guessed I am new to all of this.

Peter
 
D

Doug Robbins - Word MVP

I assume that you mean a combobox as I had suggested, and not a ListBox. To
get the selection to go to the item that you start typing, set the
MatchEntry attribute of the ComboBox to

0 - fmMatchEntryFirstLetter

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

Peter

Fantastic ... works just as you said.

And even better if I set "Match Entry" to "1 -fmMatchEntryComplete" it will
allow me to type enough letters to make the item unique and scroll to that
item.

Peter Evans
 
P

Peter

Greg and Doug (and others)

Thanks to your help so far. I can now scroll through the combolist (or type
the first couple of characters) to find the name of the autotext entry and
then click the the INSERT AS TEXT" button to insert it into the doucment or
another button to insert it as a comment. This is Good.

BUT if the autext entry contains an image the inserted item contains
something like "* EMBED Equation.DSMT4 **" and not the image. If I insert it
using INSERT > AUTOTEXT then the original with the image is inserted.

I have been using
ActiveDocument.Comments.Add Range:=Selection.Range,
_Text:=txtAutotextValue.Text

or even the following to try to get the complete value of autotext item 87

Selection.InsertAfter NormalTemplate.AutoTextEntries(87)

But all I get entered is the text of the item and not the complete item.
How can I insert the real item?

The reason that I am using my own button to insert the item is that I also
want to add other items to the comment or the text.
 
G

Greg Maxey

Peter,

You insert an autotext entry like this:

NormalTemplate.AutoTextEntries(87).Insert Selection.Range, True

You CAN'T insert a drawing object in a comment. The following example
illustrates:

Sub Test()
Dim oRng As Word.Range
Dim oCom As Comment
Set oCom = ActiveDocument.Comments.Add(Range:=Selection.Range, Text:="")
NormalTemplate.AutoTextEntries("87").Insert oCom.Range, True
End Sub
 
P

Peter

Thanks Greg ... another step closer

And even better I have found out that while
NormalTemplate.AutoTextEntries(autoTextItemNum).Add oCom.Range, True

is not supported

NormalTemplate.AutoTextEntries(autoTextItemNum).Insert oCom.Range, True

is Ok and it allows you to insert an autotext entry containing a drawing
into a comment under VBA in the same way you can if you are using the
keyboard.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top