PDA

View Full Version : ActiveX Object kills CC!



max76
06-05-2017, 01:42 PM
Hi everyone,

I'm writing because I've encountered a problem. I have attached a file so that you can better understand what I'm talking about. My VBA project is much bigger and more complext but I created a very very small extract to focus on the problem I bumped into.

I have a template that generates a document with CC. If you click on the CC_2 (to simplify everything I used an "OnEnter" event) you can see that the macro is working fine (the message box is displayed). However, if you click on the CC on the left-hand side (this will add an ActiveX button to the active document via VBA) all the CC macros are killed!! As a matter of fact entering the CC's won't trigger any macro anymore.

I've done some reading online but I didn't find anything that can help. Someone was mentioning that variables declared inside subroutines/functions might be disabled but this is not the case since I did not declare any variables. Yet, the macros are totally killed.

I'd very grateful if someone could shed some light on this disappointing glitch.

Thank you in advance for your support.

Massimo

SamT
06-05-2017, 02:47 PM
Just curious. I don't do a lot of Word VBA... What is a CC?

gmaxey
06-05-2017, 05:27 PM
Probably a Content Control

SamT
06-05-2017, 05:36 PM
OK. Not in Office XP/2002

gmaxey
06-05-2017, 05:50 PM
The problem appears to be an automation error associated with trying to use a building block to insert ActiveX objects. This seems to work:


Sub Document_New()
ActiveDocument.AttachedTemplate.BuildingBlockEntries("Test").Insert Where:=Selection.Range, RichText:=True
End Sub
Sub Document_ContentControlOnEnter(ByVal ContentControl As ContentControl)
Set CC = ContentControl
Dim oX As InlineShape
If CC.Tag = "CC_1" Then
Selection.GoTo What:=wdGoToBookmark, Name:="Test"
Set oX = Selection.InlineShapes.AddOLEControl("Forms.CommandButton.1", Selection.Range)
oX.OLEFormat.Object.Caption = "Button"
ElseIf CC.Tag = "CC_2" Then
MsgBox "Content Controls are working"
End If
End Sub

max76
06-06-2017, 12:33 PM
Hi Greg,

thank you very much for your reply. Unfortunately though even this code has killed the macros :(. I use Word 2010.

By the way, the ActiveX object that I really need to insert is an Image control http://www.vbaexpress.com/forum/image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB8AAAAeCAIAAABbkFLLAAACEElEQVRIia1VOY4C MRBs23Mwg8RjIeANI5EhEfEFIgQPIOYjZCTMga8NWngbHzMs2gpG4KNc3V1ug/0MxpgPV1LAF3u Z09p/B/tyEK5pJTGGGOMUgpHtNYpOrcRf4A3QXmRFF5gjDHGAEAIoZT6JBqgRA4oGQDyPL9cLt7Z5/O5rmsAcIN043RmVqtVWZapmBDP57Ou66ZppJRU4gT7crnknN/v9/BUb3Pf9wCw3 9TWfLZpZRVVQ3D4JE6Xd738XgsFguUP5EZpZTLpic8z3MA4JxHDSOECLdYzzMoPBojugUgfvvyP I Ov7EDwPV6jaqg7GFwm80mGvSbFirN86hj11rjCE0RKkt6BlczxiypWJZl/AWk5gQeHf3rNP2KlVIiO5UzAroY2cML/Mve9z1jjBquLEvH5eRT0BowxrAj0Wq9JdrTTlXQvNsAmNVwyvfM8Xj0qEPPUODser0eqyquU0oV RRFKG2F3syh8rM9gX3RdiR6cZRm2zDD8ruuwYBParbVa66qq2rb11kXbg7W2bVt0SzSmSKS73Y5 z3nUdZQm/9mXiw EQKvA9Q7HdbukBIbTWt9ttPp fTqeRhzD5rg7DwDkXQjRN4/Y7h8xms6IonMHDRh1nDw jnQAfVaxhVPJEVVPvnJRSa42M1Hxersfu6ngQkysnOvDXSPk1qX3S758g4hnapj32v57xA7MWdN 1a0xC9AAAAAElFTkSuQmCCas you can see in my newly attached file. Inserting the ActiveX through a building block has the advantage to allow me to have a "ready-to use" ActiveX (the image control is embedded in the template file) without the need of an external image to use to load into the ActiveX Image Control.

I really hope that this can be achieved because it's my missing piece :)

Thank you again.

Massimo