Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
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
  #2  
Old 04-19-2015, 10:07 PM
Unk Unk is offline VBA and Word basics help Windows 7 64bit VBA and Word basics help Office 2010 64bit
Novice
VBA and Word basics help
 
Join Date: Apr 2015
Posts: 3
Unk is on a distinguished road
Default

gmayor:

Thanks, I was saving it as a macro-enabled doc, the problem seems to have been that I was putting the code in the project (in the document, basically) rather than in a template. I moved it into the normal template and the code now stays when I close and reopen. I think creating a template for this document and then creating new ones from that will be the way to go, just learning about all that,

Thanks very much for the advice about the placeholder text, that works.
Reply With Quote
Reply



Other Forums: Access Forums

All times are GMT -7. The time now is 11:40 PM.


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