My document shows a "landing" form that provides command buttons for the various functions (Waivers, Invoices, Roster and Notary). I coded the document heading in Times New Roman 14 Bold.
Each of the subforms replaces the Heading, and in the case of the Invoice, replaces both the header and footer with a logo image.
In anticipation of restoring the Heading when the subforms unload, the code below shows my attempt to capture the default heading before invoking the subforms.
I am able to restore the text, but the style is lost, defaulting to Calabri 11 Normal. I've resorted to testing with a module (so as not to corrupt my main application). Here's the code
Code:
Sub Main()
Dim strCurrentHeading As String
Dim objHeaderStyles As Object
'clicking heading text shows Times New Roman 14 Bold
strCurrentHeading = Word.ActiveDocument.Sections(1).Headers(1).Range.Text
Set objHeaderStyles = Word.ActiveDocument.Styles(wdStyleHeading1)
'debug print Styles show Calibri 11 Normal
'Load Header
Word.ActiveDocument.Sections(1).Headers(1).Range.Text = ""
'Restore Heading
'loosely based on: https://stackoverflow.com/questions/56697719/_
how-to-change-style-of-some-texts-to-style-of-heading-1-without-affect-rest-of-t
'debug print Styles show Calibri 11 Normal
With ActiveDocument.Styles(wdStyleHeading1)
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Font.Name = "Times New Roman"
.Font.Size = 14
.Font.Bold = True
End With
'debug print Styles show Calibri 11 Normal
Word.ActiveDocument.Sections(1).Headers(1).Range.Text = strCurrentHeading
'debug print Styles show Calibri 11 Normal
Exit Sub
...
I've checked the immediate window at the places indicated and the font remains Calabri 11 Normal. I also tried the "... = strCurrentHeading" both before and after the "With ActiveDocument.Styles ..." statment.