Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 06-23-2021, 10:27 PM
gmayor's Avatar
gmayor gmayor is offline Word 2019 will not properly run macro Windows 10 Word 2019 will not properly run macro Office 2019
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

You code does exactly the same in earlier Word versions?
The following modification will copy the original table to the end of the table each time it is used. Set the value of iRows to the number of rows in Table 2.
As implied by Andrew, you should be thinking about converting the form to use content controls rather than legacy form fields for the future.
https://www.gmayor.com/insert_content_control_addin.htm
has an option to do that, but it won't modify your code to work with the changed fields.



Code:
Private Sub CommandButton1_Click()
Dim oRng As Range
Dim oFld As FormFields
Dim i As Integer, j As Integer
Const iRows As Integer = 2    'The number of rows in table 2

    If ActiveDocument.ProtectionType <> wdNoProtection Then
        ActiveDocument.Unprotect
    End If
    With ActiveDocument
        Set oRng = ActiveDocument.Tables(2).Range
        oRng.Collapse wdCollapseEnd
        For i = 1 To iRows
            oRng.FormattedText = ActiveDocument.Tables(2).Rows(i).Range.FormattedText
            Set oFld = oRng.FormFields
            For j = 1 To oRng.Fields.Count
                If oFld(j).Type = wdFieldFormDropDown Then
                    oFld(j).Result = oFld(j).DropDown.ListEntries(1).Name
                Else
                    oFld(j).Result = ""
                End If
            Next j
            oRng.Collapse wdCollapseEnd
        Next i
    End With
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
__________________
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
 

Tags
macro, macro error



Similar Threads
Thread Thread Starter Forum Replies Last Post
What's new in Word 2019, Excel 2019 and Outlook 2019 and Why upgrade to Office 2019 is recommended? einfomail Office 0 07-25-2019 11:49 AM
PgUp/PgDn not working as expected in Word 2019; macro workaround? AmyJSchneider Word VBA 0 01-19-2019 03:45 PM
Word 2019 will not properly run macro Macro Enabled Word Doc Does not Properly Work on Different Machine danjoe Word VBA 3 10-19-2017 05:49 AM
Macro does not run properly dherr Word VBA 2 02-19-2015 08:50 AM
Word 2000 Macro not working properly brianlb Word VBA 1 07-01-2009 07:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:18 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