Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-27-2016, 03:02 PM
macropod's Avatar
macropod macropod is offline Where to go from here? Windows 7 64bit Where to go from here? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,513
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default


Well, for starters, your code is nothing like that found in any of the links I posted. The link under the heading 'Dropdown Content Control Population from Excel' above is all you need to populate a dropdown content control's text and the corresponding values from Excel. The other links mostly show how you might use content controls for other kinds of processing.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 03-27-2016, 03:20 PM
highrise955 highrise955 is offline Where to go from here? Windows 10 Where to go from here? Office 2013
Advanced Beginner
Where to go from here?
 
Join Date: Mar 2016
Posts: 37
highrise955 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Well, for starters, your code is nothing like that found in any of the links I posted. The link under the heading 'Dropdown Content Control Population from Excel' above is all you need to populate a dropdown content control's text and the corresponding values from Excel. The other links mostly show how you might use content controls for other kinds of processing.
Except I can't make heads or tails what's going on in all that code. All I want to do is populate a simple listbox or combobox with the values from an excel spreadsheet when the document is opened. It seems like it would be so simple but every video or tutorial I find never quite hits the mark.
Reply With Quote
  #3  
Old 03-27-2016, 05:19 PM
macropod's Avatar
macropod macropod is offline Where to go from here? Windows 7 64bit Where to go from here? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,513
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by highrise955 View Post
Except I can't make heads or tails what's going on in all that code. All I want to do is populate a simple listbox or combobox with the values from an excel spreadsheet when the document is opened. It seems like it would be so simple but every video or tutorial I find never quite hits the mark.
Which is precisely what the code does. All you need to do is point the code to your workbook & worksheet, by adjusting the lines:
StrWkBkNm = "C:\Users\" & Environ("Username") & "\Documents\Workbook Name.xls"
StrWkShtNm = "Sheet1"
As coded, the macro expects the dropdown to be populated to be the first one in the document, but I'm sure you can see where you can change that in the code.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 03-29-2016, 01:10 AM
highrise955 highrise955 is offline Where to go from here? Windows 10 Where to go from here? Office 2013
Advanced Beginner
Where to go from here?
 
Join Date: Mar 2016
Posts: 37
highrise955 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Which is precisely what the code does. All you need to do is point the code to your workbook & worksheet, by adjusting the lines:
StrWkBkNm = "C:\Users\" & Environ("Username") & "\Documents\Workbook Name.xls"
StrWkShtNm = "Sheet1"
As coded, the macro expects the dropdown to be populated to be the first one in the document, but I'm sure you can see where you can change that in the code.

OK, I think I figured it out. I got the code to work but I have one final question...

Code:
With xlWkBk.Worksheets(StrWkSht)
    ' Find the last-used row in column A.
    LRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    ' Populate the content control,
    ActiveDocument.ContentControls(4).DropdownListEntries.Clear
    For i = 1 To LRow
      ActiveDocument.ContentControls(4).DropdownListEntries.Add Text:=Trim(.Range("A" & i)), Value:=Trim(.Range("B" & i))
    Next
  End With
How do I exclude Row 1 from the worksheet when it populates the DropdownList? I'm using that row as the column titles. Better yet, can I specify a specific row to start the .Range at?

Your input (and patience) is very much appreciated.
Reply With Quote
  #5  
Old 03-29-2016, 02:19 AM
macropod's Avatar
macropod macropod is offline Where to go from here? Windows 7 64bit Where to go from here? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,513
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by highrise955 View Post
OK, I think I figured it out. I got the code to work but I have one final question...
...

How do I exclude Row 1 from the worksheet when it populates the DropdownList? I'm using that row as the column titles. Better yet, can I specify a specific row to start the .Range at?
That's as easy as:
For i = 2 To LRow
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Other Forums: Access Forums

All times are GMT -7. The time now is 03:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft