![]() |
|
|
|
#1
|
|||
|
|||
|
I would like to know how i would go about changing a dropdown box in mulitple documents and change the name of the dropdown name.
currently the dropdown is named 'dropdown1' it needs to be changed to 'drpVessel'. does any one have any suggestion the best way around this? |
|
#2
|
||||
|
||||
|
What kind of dropdown and, aside from the name change, what other changes?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Quote:
Content Control dropdown list, the name of the dropdown and the content of the dropdown list. |
|
#4
|
||||
|
||||
|
So which do you want to change - the tag or the title?
As for the content, what do you want to do - add items, delete items, change their display names or values, something else? If the changes are substantial it may be simpler to delete the existing controls & replace them with entirely new ones.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#5
|
|||
|
|||
|
Quote:
some of them are from 2003-2007 which have Bookmark so would like to change the bookmark name, if I am correct in thinking that is how content control dropdown work in 2003-2007. |
|
#6
|
||||
|
||||
|
One possibility is to use a variation of the following function in conjunction with http://www.gmayor.com/document_batch_processes.htm which will handle the files and folders.
Make whatever changes to 'oCC' that you require and the add-in will do the same for all matching files in the folder. Code:
Function Dropdown(oDoc As Document) As Boolean
Dim oCC As ContentControl
On Error GoTo Err_Handler
For Each oCC In oDoc.ContentControls
If oCC.Title = "Dropdown1" Then
With oCC
.Title = "drpVessel"
.Tag = .Title
With .DropdownListEntries
.Clear
.Add "Item 1"
.Add "Item 2"
.Add "Item 3"
.Add "Item 4"
End With
End With
Exit For
End If
Next oCC
Dropdown = True
lbl_Exit:
Exit Function
Err_Handler:
Dropdown = False
Resume lbl_Exit
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#7
|
||||
|
||||
|
Content controls were launched in Word 2007, and improved in 2010. They are not compatible with 2003. I raised an eyebrow when you mentioned the name Dropdown1 which suggested legacy form fields as by default content control dropdowns do not have titles, and if you were adding one you would surely type something more meaningful.
The code I posted will not of course work with legacy form fields. For that to work we would need more information about whether the form is protected and whether it is protected with a password. Now also you are talking about 'some' of the documents. A batch process can accommodate different document types, but it will perform the same task on each.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#8
|
|||
|
|||
|
Quote:
I have docs made in 2003, 2007 and 2010. What info do you need. furthermore have have programmed to convert all 2003-2007 docs to be 2010 can that help? Last edited by QA_Compliance_Advisor; 09-12-2014 at 12:52 AM. Reason: more info |
|
#9
|
||||
|
||||
|
Can you attach a sample document so we can see what we are dealing with?
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#10
|
|||
|
|||
|
Quote:
here is a sample |
|
#11
|
||||
|
||||
|
OK, it is confirmed a form field and the document is unprotected, so the following will handle that. You can re-activate the commented out list section to change the vessel names.
This also revealed a minor bug in my batch process when run in Word 2010 that has now been fixed in version 2.3. Code:
Function Ddown(oDoc As Document) As Boolean
Dim oFF As FormField
On Error GoTo Err_Handler
For Each oFF In oDoc.FormFields
If oFF.name = "Dropdown1" Then
With oFF
.name = "drpVessel"
'With .Dropdown.ListEntries
' .Clear
' .Add "Item 1"
' .Add "Item 2"
' .Add "Item 3"
' .Add "Item 4"
'End With
End With
Exit For
End If
Next oFF
Ddown = True
lbl_Exit:
Exit Function
Err_Handler:
Ddown = False
Resume lbl_Exit
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#12
|
|||
|
|||
|
Quote:
Could being a bit dense, how do i incorporate this into having this automate process for every document in subfolders? |
|
#13
|
|||
|
|||
|
Quote:
If dropdown list entry = "Select Vessel" then carry out the change (obviously it probably aint that simple) |
|
#14
|
||||
|
||||
|
It probably is
The Select Vessel prompt will be the first item in the list so we can read that instead of the field name. The only time you might have a problem is if there are two similar dropdowns in the same document. Only one of them can be called 'drpVessel'. The macro therefore only processes the first such field. For multiple such fields in the same document, you would have to introduce a counter to add to the name.Code:
Function Ddown(oDoc As Document) As Boolean
Dim oFF As FormField
Dim i As Long
On Error GoTo Err_Handler
For Each oFF In oDoc.FormFields
If oFF.Type = wdFieldFormDropDown Then
If InStr(1, LCase(oFF.Dropdown.ListEntries(1).Name), "select vessel") > 0 Then
With oFF
.Name = "drpVessel"
'With .Dropdown.ListEntries
' .Clear
' .Add "Item 1"
' .Add "Item 2"
' .Add "Item 3"
' .Add "Item 4"
'End With
End With
Exit For
End If
End If
Next oFF
Ddown = True
lbl_Exit:
Exit Function
Err_Handler:
Ddown = False
Resume lbl_Exit
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#15
|
||||
|
||||
|
You will need the add-in which handles the folders and sub folders - http://www.gmayor.com/document_batch_processes.htm
which I referred to in my first post. Run the above code as a custom process. The instructions are on the web page.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
| Tags |
| automatically, dropdown, replace |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Multiple entries in dropdown lists
|
paul_pearson | Word VBA | 154 | 11-08-2025 03:51 PM |
| Duplicating entries on multiple tabs automatically | jbexley | Excel | 0 | 08-28-2014 04:48 PM |
Captions automatically updating all previous entries
|
jhats | Word | 1 | 07-29-2014 11:53 PM |
| Dropdown list, Macro | shield5 | Excel Programming | 7 | 10-27-2013 01:51 AM |
| Change cell color everytime a value is selected in dropdown list | angelica_gloria | Excel | 4 | 01-27-2012 06:47 PM |