0
votes

I have a pretty large template (in terms of macros) and I've created a new module that is called when the user does a specified shortcut on the keyboard. The Macro does nothing more but call "ThisDocument.HideComboBoxes".

"HideComboBoxes" is a Sub in ThisDocument, which does the obvious: hide all combo boxes in the document.

The code works fine as long as I'm working with the template.

If I render a new document out of it (a docx file) the shortcut does not work anymore (which is kinda obvious because the ThisDocument is now empty for the document).

How do I access the template's ThisDocument from within the document or how can I hide the combo boxes from within the docx?

Here's the code for hiding the comboboxes in the template's ThisDocument:

Sub HideComboBoxes()
 Me.ComboBoxConfi.Width = 1
 Me.ComboBoxConfi.Height = 1
 Me.ComboBoxState.Width = 1
 Me.ComboBoxState.Height = 1
End Sub

Thanks in advance

1

1 Answers

1
votes

You need to put the code in a "normal" module. This will require changing the calls to the ActiveX controls, which is a pain, but works.

Assuming the ActiveX controls are managed on the document surface as InlineShapes a call would look like this:

Dim cbConfi as Object 'or as MsForms.ComboBox to get Intellisense
Set cbConfi = ActiveDocument.InlineShapes([indexvalue]).OLEFormat.Object
cbConfi.Width = 1

If you don't want to rely on the index value (position of the control in the InlineShapes collection) you can select the ActiveX control and assign a bookmark to it. Or you can loop the collection of ActiveX controls, check the Type and, if it's a OLE object, check whether the Class type is MSForms.Combobox and then via OLEFormat.Object.Name whether its the right one.