plain text content control enabled/disabled depending on option button enabled

noobprogrammergirl

New Member
Joined
May 8, 2017
Messages
10
I have been trying to figure out how to make this work for probably 25 hours over the past 3 days, googling and testing, reading and implementing, but I cannot for the life of me figure this out.

I am trying to create a form in Word that we can use to keep track of experiments that we do in our oncology lab.
I would expect you can do the following:

I added two option buttons that are activated mutually exclusively (you can click one or the other).
Below each option, I put a plain text content control in which scientist will describe some aspect of the chosen option.
I *WANT* to activate the plain text content control under the option button above it, if and only if the option button is activated. Or, another way about it, once a particular option button is chosen, I only want the plain text content control below that button to be available for typing and I want the other one to be inactive (cannot type inside because you didn't choose its 'associated' option).

I think I found ways to do this if I create the plain text content control *from* code in VBA. I also think I found a way to do this if, instead of plain text content control, I use a text box (just called textbox1, for example). BUT I really want to use the plain text content control rather than a text box. I figure I should be able to use code to inactivate that plain text content control that I inserted using the UI on the developer tab. However, I cannot figure out how to identify (call? designate? point to?) the UI-inserted plain text content control in VBA code so that I can say:

if optionbutton1.enabled = true then
'that plain textCC*'.enabled = true
else
'same plain textCC as above'.enabled = false

* the particular plain text content control that I added via the UI... it has a tag (i.e. "plaintext1", but cant figure out how to call it by its tag either.

I am such a noob that I really dont understand any of the error messages at all... I am always getting compile errors and variable not defined and Identifier under cursor is not recognized because I cant seem to use the right code to refer to that plain text content control.

Can I do what I am asking or is it impossible and I wasted all these hours trying to do something that cant be done and I need to kill the OCD craziness inside me and force myself to use a text box or code the plain text content control directly from VBA?

Thank you for humoring me. Cheers!
 
You need to ensure the macro code is saved in the document's own 'ThisDocument' code module (i.e. not in its template's 'ThisDocument' code module) and that the document is saved in the .docm format. The macro will then travel with the document itself and be usable as-is. The only thing a recipient might need to do is to enable the macro when prompted upon opening the document.

Having the code in its own 'ThisDocument' module, saving in .docm format, and enabling macros on the destination comp was how I originally was trying to pass it along, but it did not work that way either. That is why I started trying to send it as a separate add-in =\
 
Upvote 0

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Did you check whether the code was actually in the docm document when opened on the other computer?
 
Upvote 0
Did you check whether the code was actually in the docm document when opened on the other computer?

It doesnt carry over, even though it is present in the original doc (saved as docm) before I email it. I started searching around online and that was when I started coming across various sources saying you cannot save code to the doc and expect it to move with the doc... it cannot transfer and is only local. The sources said you have to create a separate doc that included the code and you have to put it in the add-ins startup or template folders.
 
Upvote 0
It doesnt carry over, even though it is present in the original doc (saved as docm) before I email it.
Being able to 'see' the code from the document doesn't mean it's in the document; you'll see code that's in the document's template just as well. Saving such a document in the docm format doesn't transfer any code from the template to the document. That's why I said you needed to check which it was in. If it's not present in the received email, it wasn't present in the sent email!
I started searching around online and that was when I started coming across various sources saying you cannot save code to the doc and expect it to move with the doc... it cannot transfer and is only local. The sources said you have to create a separate doc that included the code and you have to put it in the add-ins startup or template folders.
Whatever those sources were, they're entirely wrong about that. If you email a docm file, the entire file, including any macros in it, is sent. There most certainly isn't a need to create an addin. The only time code doesn't travel with the document using it is if the code is in the template instead of in the document.
 
Upvote 0
Being able to 'see' the code from the document doesn't mean it's in the document; you'll see code that's in the document's template just as well. Saving such a document in the docm format doesn't transfer any code from the template to the document. That's why I said you needed to check which it was in. If it's not present in the received email, it wasn't present in the sent email!

Whatever those sources were, they're entirely wrong about that. If you email a docm file, the entire file, including any macros in it, is sent. There most certainly isn't a need to create an addin. The only time code doesn't travel with the document using it is if the code is in the template instead of in the document.


Ok I played with it a bit and somehow was able to make sure the code was not in the template, but the actual document. the whole template thing was hard to track and is not very clear to me. anyhow, I think it is WORKING! Of course I'll be back if not, but for now, THANK YOU! The code is finally carrying over, at least when I've tested it myself. We'll see when my co-workers get back to me whether it works for them or not.
 
Upvote 0
I am back yet again. Turns out people in my lab that use Macs cannot use docs with this code because Macs are not compatible with "activex" controls (i.e. the option buttons). I tried to replace the option buttons with check boxes and tagged them as "checkplatelight" and "checkincucyte".

Can you spot why the following code cant work?


Private Sub Document_New()
End Sub
Private Sub Document_open()
With ActiveDocument
If ActiveDocument.SelectContentControlsByTag("checkplatelight").Item(1).Checked Then
ActiveDocument.SelectContentControlsByTag("check1").Item(1).Checked = False
ActiveDocument.SelectContentControlsByTag("check2").Item(1).Checked = False
ActiveDocument.SelectContentControlsByTag("check3").Item(1).Checked = False
ActiveDocument.SelectContentControlsByTag("checkincucyte").Item(1).Checked = False
ActiveDocument.SelectContentControlsByTag("Incucyteplaintext1").Item(1).LockContents = True
ActiveDocument.SelectContentControlsByTag("Incucyteplaintext2").Item(1).LockContents = True
ActiveDocument.SelectContentControlsByTag("check1").Item(1).LockContents = True
ActiveDocument.SelectContentControlsByTag("check2").Item(1).LockContents = True
ActiveDocument.SelectContentControlsByTag("check3").Item(1).LockContents = True
Else
ActiveDocument.SelectContentControlsByTag("Incucyteplaintext1").Item(1).LockContents = False
ActiveDocument.SelectContentControlsByTag("Incucyteplaintext2").Item(1).LockContents = False
ActiveDocument.SelectContentControlsByTag("check1").Item(1).LockContents = False
ActiveDocument.SelectContentControlsByTag("check2").Item(1).LockContents = False
ActiveDocument.SelectContentControlsByTag("check3").Item(1).LockContents = False
End If
If ActiveDocument.SelectContentControlsByTag("checkincucyte").Item(1).Checked Then
ActiveDocument.SelectContentControlsByTag("platelightplaintext1").Item(1).LockContents = True
ActiveDocument.SelectContentControlsByTag("platelightplaintext2").Item(1).LockContents = True
ActiveDocument.SelectContentControlsByTag("platelightcombo1").Item(1).LockContents = True
ActiveDocument.SelectContentControlsByTag("checkplatelight").Item(1).Checked = False
Else
ActiveDocument.SelectContentControlsByTag("platelightplaintext1").Item(1).LockContents = False
ActiveDocument.SelectContentControlsByTag("platelightplaintext2").Item(1).LockContents = False
ActiveDocument.SelectContentControlsByTag("platelightcombo1").Item(1).LockContents = False
End If
End With
End Sub

thank you for any help!
 
Upvote 0
I am back yet again. Turns out people in my lab that use Macs cannot use docs with this code because Macs are not compatible with "activex" controls (i.e. the option buttons). I tried to replace the option buttons with check boxes and tagged them as "checkplatelight" and "checkincucyte".

Can you spot why the following code cant work?
ActiveX controls have never been supported on the Mac platform. Even content controls have only limited support of the Mac platform. For wide support, you would need to replace both with formfields - and a suitably-recoded macro. Even then, your form wouldn't work on Mac Word 2008, because that version lacks macro support.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top