Solved

Content control in Word

Posted on 2013-06-17
2
418 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
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…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
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.

710 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