Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 04-19-2015, 09:47 PM
gmayor's Avatar
gmayor gmayor is offline VBA and Word basics help Windows 7 64bit VBA and Word basics help Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The code disappears almost certainly because you are saving the document as DOCX format which doesn't support macros, rather than DOCM format, which does.

Probably better still, save it as a macro enabled template (DOTM format) and create new documents from the template (File > New).

If you want the macro to ignore the default text in the list box, then leave in the two optional lines. The Debug.Print ContentControl.Range line is not required other than for testing.

Code:
Option Explicit

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    If ContentControl.Tag = "TypeSelect" Then
        If Not ContentControl.Range = ContentControl.PlaceholderText Then 'Optional
            Select Case ContentControl.Range
                Case "Task"
                    ActiveDocument.ContentControls(2).Range = "Enter Steps"
                Case "Concept"
                    ActiveDocument.ContentControls(2).Range = "Enter Descriptive Content"
                Case Else
                    ActiveDocument.ContentControls(2).Range = "Enter Reference Data"
            End Select
        End If
    End If 'Optional with previous optional line
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
 



Other Forums: Access Forums

All times are GMT -7. The time now is 12:32 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft