Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-12-2014, 02:20 AM
gmayor's Avatar
gmayor gmayor is offline VBA Dropdown change list Entries automatically Windows 7 64bit VBA Dropdown change list Entries automatically Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #2  
Old 09-12-2014, 04:29 AM
QA_Compliance_Advisor QA_Compliance_Advisor is offline VBA Dropdown change list Entries automatically Windows 7 32bit VBA Dropdown change list Entries automatically Office 2010 32bit
Advanced Beginner
VBA Dropdown change list Entries automatically
 
Join Date: Jul 2014
Posts: 44
QA_Compliance_Advisor is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
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

Could being a bit dense, how do i incorporate this into having this automate process for every document in subfolders?
Reply With Quote
  #3  
Old 09-16-2014, 03:06 AM
QA_Compliance_Advisor QA_Compliance_Advisor is offline VBA Dropdown change list Entries automatically Windows 7 32bit VBA Dropdown change list Entries automatically Office 2010 32bit
Advanced Beginner
VBA Dropdown change list Entries automatically
 
Join Date: Jul 2014
Posts: 44
QA_Compliance_Advisor is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
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
I have found that there is a more problamatic issue, not all dropdown that I want to change are named dropdown1, but there is a logic all the drop down in the list entry has "select Vessel". what logic would I need to have;

If dropdown list entry = "Select Vessel" then

carry out the change (obviously it probably aint that simple)
Reply With Quote
  #4  
Old 09-16-2014, 04:40 AM
gmayor's Avatar
gmayor gmayor is offline VBA Dropdown change list Entries automatically Windows 7 64bit VBA Dropdown change list Entries automatically Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
Reply

Tags
automatically, dropdown, replace



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Dropdown change list Entries automatically Multiple entries in dropdown lists paul_pearson Word VBA 151 10-18-2023 04:23 PM
Duplicating entries on multiple tabs automatically jbexley Excel 0 08-28-2014 04:48 PM
VBA Dropdown change list Entries automatically 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:41 PM.


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