View Single Post
 
Old 12-17-2014, 11:01 PM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit 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

There are several ways that you could handle this. I suspect my preference would be to save the core document as a macro enabled template and all the tables as separate Autotext/Building Block entries in that template.

You could then create a simple userform with four radio buttons, the selection from which would insert the appropriate building block in the new document created from the template.

I would start with the document template having an autotext field inserted to display one of the autotext entries. It is then a simple matter to replace the field code according to the choice of option button.

The following macro will change the field. Call it from the userform e.g.

Code:
Sub ChangeAutoText(strText As String)
Dim oFld As Field
Dim oRng As Word.Range
    Set oRng = ActiveDocument.Range
    For Each oFld In oRng.Fields
        If oFld.Type = wdFieldAutoText Then
            oFld.Locked = False
            oFld.Code.Text = Replace(oFld.Code, oFld.Code.Text, "AUTOTEXT " & strText)
            oFld.Update
            oFld.Locked = True
            Exit For
        End If
    Next oFld
lbl_Exit:
    Exit Sub
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