![]() ![]() ![]() For more info, visit our Terms of Use page. This may influence how and where their products appear on our site, but vendors cannot pay to influence the content of our reviews. We may be compensated by vendors who appear on this page through methods such as affiliate links or sponsored partnerships. This article provides step-by-step instructions for color customizing your drop-down list in Microsoft Excel. The file does exist and column A of sheet1 has data from A1 down to A106.How to add color to a drop-down list in Excel When I run the macro I get the error message: "Run-time error '1004': Application-defined or object-defined error". I changed the location for the StrWkBkNm file. I created a macro on Word called Dropdownlist and I pasted the suggested code there. I wanted to fill it with a list of clients that I have on column A of Sheet1 on an Excel file called "Clients List". I named the dropdown list as "Clients" and it has no options entered yet. I have a word template file with just one dropdown list created. Hi, was asking about the very first code on this thread (I'm sorry if I didn't place my question correctly). MsgBox (1).IDYou can run either from the VB Immediate window. via Alt-F8>UpdateDropDown>OK).įor PC macro installation & usage instructions, see: Installing Macrosįor Mac macro installation & usage instructions, see: Word:mac - Install a MacroĬode: Debug.Print (1).ID UpdateDropDown) so that it will only run on demand (e.g. Alternatively, you could rename the macro (e.g. You can do that just by saving it as a template (once you've made the code change but before you've made any selections or other edits that you don't want to appear in every new version of this document). You may need to create a specific template for this document. To prevent that, change the macro's name from 'Document_Open' to 'Document_New' and add it to the document's template. Note: For the above code to work, every Dropdown List Entry and every Dropdown List Value must be unique.ĭo be aware that the above code will re-populate the dropdown every time you open the document, wiping out whatever you'd previously selected. Set xlWkBk = Nothing: Set xlApp = NothingĮnd SubIf you use the code to populate the content control's 'value', you can then supplement the above code with a content control on-exit macro to populate a dependent content control with that 'value'. 'ActiveDocument.SelectContentControlsByTitle("ID")(1).DropdownListEntries.Add _ 'or, for example, to add the contents of column B to the content control's 'value': ' content control Text and the values from columns B-E as the content controlĪctiveDocument.SelectContentControlsByTitle("ID")(1).DropdownListEntries.ClearĪctiveDocument.SelectContentControlsByTitle("ID")(1).DropdownListEntries.Add _ ' Populate the content control titled 'ID', with Column A for the 'ID' as the Workbooks.Open(FileName:=StrWkBkNm, ReadOnly:=True, AddToMRU:=False) MsgBox "Cannot find the designated workbook: " & StrWkBkNm, vbExclamation StrWkBkNm = "C:\Users\" & Environ("Username") & "\Documents\Workbook Name.xls" 'Note: A VBA Reference to the Excel Object Model is required, via Tools|Referencesĭim xlApp As New Excel.Application, xlWkBk As Excel.Workbookĭim StrWkBkNm As String, StrWkShtNm As String, LRow As Long, i As Long ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |