txpmower
01-19-2017, 03:37 PM
Hi,
I just started coding in VBA on Monday and have run into some challenges.
I am trying to develop a Form in MS Word and one of the Form Fields is called "subject" and it has a drop down menu with a list of subjects
1. If any subject is selected from the drop down menu, I want to be able to write the selection to the header and footer
2. The font color of the item written to the header and footer would vary depending on the item selected.
3. The item written to the header and footer would be preceeded by the word "Subject:" in standard black font
This is the code snipet I have put together so far...any help and insight would be greatly appreciated.
'This subroutine sets the classification in the header
Sub SetHeadersFooters()
Select Case ActiveDocument.FormFields("ddsubject").Result
Case "MATH"
ActiveDocument.Unprotect Password:="mathematics"
For i = 1 To ActiveDocument.Sections.Count
With ActiveDocument.Sections(i)
.Headers(wdHeaderFooterPrimary).Range.Text = "SUBJECT: MATHEMATICS"
.Footers(wdHeaderFooterPrimary).Range.Text = "SUBJECT: MATHEMATICS"
Selection.Font.ColorIndex = wdRed
End With
Next
Case "ENGLISH"
ActiveDocument.Unprotect Password:="topics"
For i = 1 To ActiveDocument.Sections.Count
With ActiveDocument.Sections(i)
.Headers(wdHeaderFooterPrimary).Range.Text = "SUBJECT: ENGLISH"
.Footers(wdHeaderFooterPrimary).Range.Text = "SUBJECT: ENGLISH"
Selection.Font.ColorIndex = wdRed = wdBlue
End Select
End Sub
I just started coding in VBA on Monday and have run into some challenges.
I am trying to develop a Form in MS Word and one of the Form Fields is called "subject" and it has a drop down menu with a list of subjects
1. If any subject is selected from the drop down menu, I want to be able to write the selection to the header and footer
2. The font color of the item written to the header and footer would vary depending on the item selected.
3. The item written to the header and footer would be preceeded by the word "Subject:" in standard black font
This is the code snipet I have put together so far...any help and insight would be greatly appreciated.
'This subroutine sets the classification in the header
Sub SetHeadersFooters()
Select Case ActiveDocument.FormFields("ddsubject").Result
Case "MATH"
ActiveDocument.Unprotect Password:="mathematics"
For i = 1 To ActiveDocument.Sections.Count
With ActiveDocument.Sections(i)
.Headers(wdHeaderFooterPrimary).Range.Text = "SUBJECT: MATHEMATICS"
.Footers(wdHeaderFooterPrimary).Range.Text = "SUBJECT: MATHEMATICS"
Selection.Font.ColorIndex = wdRed
End With
Next
Case "ENGLISH"
ActiveDocument.Unprotect Password:="topics"
For i = 1 To ActiveDocument.Sections.Count
With ActiveDocument.Sections(i)
.Headers(wdHeaderFooterPrimary).Range.Text = "SUBJECT: ENGLISH"
.Footers(wdHeaderFooterPrimary).Range.Text = "SUBJECT: ENGLISH"
Selection.Font.ColorIndex = wdRed = wdBlue
End Select
End Sub