Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Content control in Word

Posted on 2013-06-17
2
Medium Priority
?
421 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 2000 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

688 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