View Single Post
 
Old 10-23-2019, 02:58 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
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 of
Default

Using content controls as hinted by Andrew is certainly a sensible approach. e.g. you could put a content control in the header of the template and title it (say) 'HeaderText' then use the following to populate it

Code:
Private Sub cmdSetClassification_Click()
' prepare header footers..
Dim oCC As ContentControl
Dim sHeadFooter As String
    Set oCC = ActiveDocument.SelectContentControlsByTitle("HeaderText").Item(1)
    sHeadFooter = txtFurtherInfo.Text
    oCC.Range = sHeadFooter
    Unload Me
End Sub
or you could write to the start or the end of the header range e.g.
Code:
Private Sub cmdSetClassification_Click()
' prepare header footers..
Dim oHeader As Range
Dim sHeadFooter As String
    Set oHeader = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
    oHeader.Collapse 1    'the start of the range or
    'oHeader.Collapse 0 'the end of the range
    sHeadFooter = txtFurtherInfo.Text
    oHeader.Text = sHeadFooter
    Unload Me
End Sub
which answers the original question regarding the overwriting of range content, but that is nowhere near as convenient should you wish to recall the userform to edit the document

You could also use bookmarks to locate the text and you will find the FillBM macro on my web site to write to the bookmarks and remark the text so that it may be recalled to the userform. I prefer content controls as they are less likely to be accidentally deleted, but that is less of an issue with headers and footers.

You may find Insert Content Control Add-In useful
__________________
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