Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 09-16-2014, 03:23 AM
macropod's Avatar
macropod macropod is offline VBA Dropdown change list Entries automatically Windows 7 64bit VBA Dropdown change list Entries automatically Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
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


Try:
Code:
Function Ddown(oDoc As Document) As Boolean
Dim oFF As FormField, i As Long, bChng As Boolean
    On Error GoTo Err_Handler
    For Each oFF In oDoc.FormFields
        With oFF
            If .Type = wdFieldFormDropDown Then
                bChng = False
                If .Name = "Dropdown1" Then
                    bChng = True
                Else
                    For i = 1 To .DropDown.ListEntries.Count
                        If .DropDown.ListEntries(i).Name = "Select Vessel" Then
                            bChng = True
                            Exit For
                        End If
                    Next
                End If
            End If
            If bChng = True Then
                .Name = "drpVessel"
                'With .Dropdown.ListEntries
                '    .Clear
                '    .Add "Item 1"
                '    .Add "Item 2"
                '    .Add "Item 3"
                '    .Add "Item 4"
                'End With
                Exit For
            End If
        End With
    Next oFF
    Ddown = True
lbl_Exit:
    Exit Function
Err_Handler:
    Ddown = False
    Resume lbl_Exit
End Function
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #17  
Old 09-16-2014, 04:36 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

amasing!

Could you explain how I could call this function from within the macro https://www.msofficeforums.com/word-...er-footer.html

not too strong in understanding how I can call a subroutine or function.
Reply With Quote
  #18  
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,137
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
  #19  
Old 09-16-2014, 04:49 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,137
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

Quote:
Originally Posted by QA_Compliance_Advisor View Post
amasing!

Could you explain how I could call this function from within the macro https://www.msofficeforums.com/word-...er-footer.html

not too strong in understanding how I can call a subroutine or function.
I had missed Paul's reply when I replied also However to call a function you call it by name and apply the named parameter e.g

Ddown ActiveDocument.

It was however intended to be used with my batch processor linked earlier in the thread which provides the folder and sub folder handling
__________________
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
  #20  
Old 09-16-2014, 06:12 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

Graham, yes it works well with your batch processor - however, since i have so many different things to do i knida want it it all done in a one click rather than processing 2000 documents six times.

so I want to use your batch processing but have all the other function called one at a time during the batch processing.

Last edited by QA_Compliance_Advisor; 09-16-2014 at 06:38 AM. Reason: spelling
Reply With Quote
  #21  
Old 09-16-2014, 07:29 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,137
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

Do you mean you want to add the following?

Code:
With wdDoc
    'Process the body
    Call Update(.Range)
    'Process textboxes etc in the body
    For Each Shp In .Shapes
        With Shp.TextFrame
            If .HasText Then
                Call Update(.TextRange)
            End If
        End With
    Next
    For Each Sctn In .Sections
        For Each HdFt In Sctn.Headers
            With HdFt
                If .LinkToPrevious = False Then
                    'Process the header
                    Call Update(.Range)
                End If
            End With
        Next
    Next
    .Close SaveChanges:=True
End With
In that case bear in mind that the document used by the code I posted is oDoc rather than wdDoc and you must no close that document from the code as the add-in takes care of that, so it is simply a matter of inserting the relevant bits of the code into the original macro

So you need to add this bit after the line
Next oFF
Don't forget to include The Update code and to declare the additional variables used here at the top of the function. I haven't tested you additional code.

Code:
With oDoc
    'Process the body
    Call Update(.Range)
    'Process textboxes etc in the body
    For Each Shp In .Shapes
        With Shp.TextFrame
            If .HasText Then
                Call Update(.TextRange)
            End If
        End With
    Next
    For Each Sctn In .Sections
        For Each HdFt In Sctn.Headers
            With HdFt
                If .LinkToPrevious = False Then
                    'Process the header
                    Call Update(.Range)
                End If
            End With
        Next
    Next
End With
__________________
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 09:12 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