Solved

Content control in Word

Posted on 2013-06-17
2
405 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now