Insert custom word template icon into word template table

94 Views Asked by At

I have Integrated a tab name "Philip Prosenber" and a button (also added custom Bulb icon for this button) to run a VBA macro using office Custom UI Editor.

My .docm template "Springer Publishing" looks like this:

My plan is to insert a textbox for the user so that they could use predefined format which should look like this (with all requirements):

But someone suggest me that to:

  1. use a table otherwise it won't get the lightbulb automatically centered vertically in the text box.
  2. Use a quick part/building block instead of using code.

so I used following code to enter a table into .docm template:

Sub Insert_Table_Textbox()
    Set newDoc = ActiveDocument
    Set mytable = _
     newDoc.Tables.Add(Range:=Selection.Range, NumRows:=1, _
     NumColumns:=2)
    mytable.Cell(1, 1).SetWidth ColumnWidth:=InchesToPoints(1.3), RulerStyle:=wdAdjustNone
    mytable.Cell(1, 2).SetWidth ColumnWidth:=InchesToPoints(5.3), RulerStyle:=wdAdjustNone
    mytable.Shading.BackgroundPatternColor = -603917569
    mytable.Cell(1, 2).Range.InsertAfter "<Enter information content here>"
    mytable.Cell(1, 1).Range.InsertAfter "icon" ''here I need to select insert icon which I already have embedded in given template.
    mytable.Cell(1, 2).Range.Select

End Sub

how do I insert that bulb icon in cell 1? so that it should look like my required Table. bulb icon is already added to template using custom user interface editor by Microsoft.

Note: I am using MS word 2010-13 both. .docm template so that anyone can use it.

2

There are 2 best solutions below

0
Rich Michaels On

You need to adjust the cell's vertical alignment and paragraph format. Here is an example code that will do that and you should modify it to integrate with your existing code.

With ActiveDocument.Tables(1).Cell(1, 1).Range
    .ParagraphFormat.Alignment = wdAlignParagraphCenter
    .Cells.VerticalAlignment = wdCellAlignVerticalCenter
End With
4
Timothy Rylatt On

An alternative method requiring no code.

Ensure that document has been saved as a template (.dotx or .dotm) Add a two cell table and format as required. Insert icon and size as required. Insert a Content Control (see Developer tab) into cell where text is to be inserted. Select table and from the Insert tab select Quick Parts, then Save Selection to Quick Part Gallery

enter image description here

In the dialog box give your building block a name and select an appropriate gallery for it. The “Custom” galleries aren’t displayed by default so are useful for custom ribbon tabs. enter image description here

Now delete the table you created.

Edit the ribbon xml for your template to add the gallery you saved the building block into.

<control idMso="CustomTablesGallery" size="large" label="Custom Tables" />

The user will insert the building block from the gallery.

enter image description here

You now have a self-contained template that can be distributed to other users without dependencies on other files.