Solved

Content control in Word

Posted on 2013-06-17
2
417 Views
Last Modified: 2013-06-17
Hi,
I have a couple of ContentControls in a Word document that I wish to reset to the first item in the list when the user clicks a button.
I have the button and some code to clear the contents of table cells, and I have tried to get the first contentcontrol (a drop list) to reset to the first list item, (line 15 in the code) but I'm struggling.
As always any help is much appreciated.
Private Sub btnEmal_Click()
On Error GoTo ErrHandler
    Dim cl1 As Cell
    Dim cl2 As Cell
    Dim tbl As Table
    Dim rng As Range
    
    Set tbl = ActiveDocument.Tables(1)
    Set cl1 = tbl.Cell(2, 2)
    Set cl2 = tbl.Cell(11, 5)
    Set rng = cl1.Range.Duplicate
    rng.End = cl2.Range.End
    rng.Delete
    
ActiveDocument.Range , ContentControls("Shift").Range = 1
Exit Sub
ErrHandler:
    MsgBox Err.Description
End Sub

Open in new window

0
Comment
Question by:Stephen Byrom
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39255029
This code assumes that the target content control is the first in the document with the title "shift".
Dim cc As ContentControl

Set cc = ActiveDocument.SelectContentControlsByTitle("Shift")(1)
cc.DropdownListEntries.Item(2).Select

Open in new window

Note that item 1 is the placeholder text and item 2 is the first in the list of added entries.
0
 
LVL 1

Author Closing Comment

by:Stephen Byrom
ID: 39255195
Brilliant!
Did exactly what I wanted.
Thanks a lot
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question