Quick Access Toolbar Macro Buttons

I have a word 2010 form that has macro buttons in the Quick Access Toolbar. One is to delete whatever section you are in (specifically the last 4 sections that are actually 4 separate forms). The other four are to insert a section (one of the 4 forms that may have been deleted). I recorded each macro, but they don't all seem to work correctly. Each of the 4 buttons to insert a section should go to the end of the document, insert a Next Page Break, insert the appropriate quick part for that section, edit the header and footer for that specific section to not link to the previous and be customized for that section. The problem I am running into is that the headers/footers are not working properly. I also think one of the macro buttons gives a Debug message. Can anyone take a look and help me out? Much appreciated!

https://onedrive.live.com/redir?resid=BBE57EBA0DFD80DF!138&authkey=!AIc9u2L2MkXXZ3w&ithint=file%2cdotm

The Macro recorder, records some horrible code, most of which you do not need and I would use code like the following

Dim rng As Range
Dim i As Long

Sub InsertConfidential

Set rng = ActiveDocument.Range
rng.Collapse wdCollapseEnd
rng.InsertBreak wdSectionBreakNextPage
Set rng = ActiveDocument.Range
rng.Collapse wdCollapseEnd
ActiveDocument.AttachedTemplate.BuildingBlockEntries("Confidential").Insert rng, RichText:=True
With rng.Sections(1)
    .Headers(wdHeaderFooterPrimary).LinkToPrevious = False
    .Footers(wdHeaderFooterPrimary).LinkToPrevious = False
End With
Set rng = rng.Sections(1).Headers(wdHeaderFooterPrimary).Range
With rng.Font
    .Name = Arial
    .Size = 8
End With
With rng.ParagraphFormat
    For i = .TabStops.Count To 1 Step -1
        .TabStops(i).Clear
    Next i
    .TabStops.Add InchesToPoints(7.88), wdAlignTabRight
End With
rng.Text = "State of Wisconsin" & vbTab & "Wisconsin Human Resourcs Handbook" & vbCr & _
    "Office of State Employment Relations" & vbTab & "Ch. 324" & vbCr & _
    "Division of Compensation and Labor Relations"
Set rng = ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary).Range
With rng.ParagraphFormat
    .TabStops.Add InchesToPoints(7.88), wdAlignTabRight
    .SpaceBefore = 0
    .SpaceAfter = 0
    .LineSpacingRule = wdLineSpaceSingle
End With
rng.Text = "OSER-DCLR-86 (Rev. 02/2013)" & vbTab & Replace(Replace(rng.Text, vbTab, ""), vbCr, "") & vbTab & "Compensation and Labor Relations" & vbCr & _
"Section 230.09 Wis. Stats." & vbTab & vbTab & "Issue Date: March 1998" & vbCr & _
"Revised: February 2013"

End Sub

I note that your form uses a mixture of Content Controls and Legacy Formfields and it would be better to replace the latter with Content Controls.

Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Thank you, Doug. I note that the mixture of content controls and form fields is intentional. The form fields are not actually used for anything except a placeholder for the user; in those spots we did not want to use content controls. Form fields only work if the document is protected, and this is not protected. They simply go away when the user types there. The parts that the user is not allowed to change are grouped.

The code you gave me seems to work great for the one section. I have three questions yet.

1. For the header, there needs to be a blank row below the text to separate the header from the first line of text. I am not sure how to code that.

2. In the footer, I need the last part "Revised: February 2013" to be right aligned, but I do not know how to code it to do that.

3. For the Project code, the header is blank, so anything in the header needs to be deleted. I am not sure how to code that. Also, everything in the footer needs to be deleted except for the page number in the center. Again, I do not know how to code that.

Can you help me further? I REALLY appreciate your help!

Lori

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

For the header use either

rng.Text = "State of Wisconsin" & vbTab & "Wisconsin Human Resourcs Handbook" & vbCr & _
    "Office of State Employment Relations" & vbTab & "Ch. 324" & vbCr & _
    "Division of Compensation and Labor Relations" & vbCr

which will add an empty paragraph, or add

rng.Paragraphs(3).ParagraphFormat.SpaceAfter = 12

which will format the last paragraph in the header with space after it.

For the footer, use

rng.Text = "OSER-DCLR-86 (Rev. 02/2013)" & vbTab & Replace(Replace(rng.Text, vbTab, ""), vbCr, "") & vbTab & "Compensation and Labor Relations" & vbCr & _
"Section 230.09 Wis. Stats." & vbTab & vbTab & "Issue Date: March 1998" & vbCr & vbTab & vbTab & _
"Revised: February 2013"

For the Project Code header, use

rng.Text = ""

For the footer, use

rng.Text = "Page "

rng.Collapse wdCollapseEnd

ActiveDocument.Fields.Add rng, wdFieldEmpty, "page"

rng.ParagraphFormat.Alignment = wdAlignParagraphCenter

Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 14, 2025 Views 60 Applies to: