![]() |
|
|
|
#1
|
||||
|
||||
|
I'd have thought it pretty obvious that you'd need to make some adjustments to the code for it to suit your particular needs - few of which you've specified. At the very least, you'd need to change the worksheet name in the code - and the accompanying discussion even draws attention to the kinds of changes you might need to make: Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#2
|
|||
|
|||
|
Sorry Marcropod,
I did make what I thought were the correct edits. I put the code in my Word VBA Code section and here is what I had done. Code:
Application.ScreenUpdating = False
'Note: A VBA Reference to the Excel Object Model is required, via Tools|References
Dim xlApp As New Excel.Application, xlWkBk As Excel.Workbook
Dim StrWkBkNm As String, StrWkShtNm As String, LRow As Long, i As Long
StrWkBkNm = "C:\Users\dlafko\Desktop\Job Titles ONly.xls"
StrWkShtNm = "Sheet1"
If Dir(StrWkBkNm) = "" Then
MsgBox "Cannot find the designated workbook: " & StrWkBkNm, vbExclamation
Exit Sub
End If
With xlApp
'Hide our Excel session
.Visible = False
' Open the workbook
Set xlWkBk = .Workbooks.Open(FileName:=StrWkBkNm, ReadOnly:=True, AddToMRU:=False)
' Process the workbook.
With xlWkBk
With .Worksheets(StrWkShtNm)
' Find the last-used row in column A.
LRow = .Cells(.Rows.Count, 1).End(xlUp).Row
' Populate the content control titled 'ID', with Column A for the 'ID' as the
' content control Text and the values from columns B-E as the content control
' value, using a "|" separator
ActiveDocument.SelectContentControlsByTitle("ID")(1).DropdownListEntries.Clear
For i = 1 To LRow
ActiveDocument.SelectContentControlsByTitle("ID")(1).DropdownListEntries.Add _
Text:=Trim(.Range("A" & i))
'or, for example, to add the contents of column B to the content control's 'value':
'ActiveDocument.SelectContentControlsByTitle("ID")(1).DropdownListEntries.Add _
Text:=Trim(.Range("A" & i)), Value:=Trim(.Range("B" & i))
Next
End With
.Close False
End With
.Quit
End With
' Release Excel object memory
Set xlWkBk = Nothing: Set xlApp = Nothing
Application.ScreenUpdating = True
End Sub
Quote:
Last edited by macropod; 04-11-2019 at 03:52 PM. Reason: Added code tags |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Changing Drop Down List to Combo Box
|
workingspade | Word | 7 | 06-13-2024 01:17 AM |
| Letter Template /w combo box list | etruz | Word | 4 | 10-31-2018 05:16 AM |
| Word 2010 Content Control help - Combo Boxes vs Drop Down List | proghy | Word | 1 | 09-16-2014 02:01 PM |
| How can I add hyperlink to open a word file from an excel combo box selection? | mahmoudramadan | Excel | 0 | 10-20-2012 10:41 AM |
| Bold list items in a combo box | DrewB | Word VBA | 0 | 07-17-2009 11:32 AM |