To automatically add a square bracket VBA code to a Word document reference

Source: Internet
Author: User

The following macro code, used in Word environments, automatically adds brackets or brackets to Word document references

' Addmarkref Macro

Dim Parag as Paragraph

Dim Selrge as Range

Dim Rge as Range

Dim Nfield as Integer

Dim Nparag as Integer

Set Selrge = Selection.Range

MsgBox "Should you choose a good reference before using the macro code?"

ActiveDocument.ActiveWindow.View.FieldShading = wdfieldshadingwhenselected

For Nparag = 1 to SelRge.Paragraphs.Count

Set rge = selrge.paragraphs (Nparag). Range

Rge. Select

Nfield = Selection.Fields.Count

For i = 1 to Nfield

Rge. Select

If Selection.Fields.Count >= 1 Then

With Selection.fields (i)

. Update

. Select

End With

Selection.cut

Selection.InsertBefore ("[")

Selection.Collapse Direction:=wdcollapseend

Selection.paste

Selection.InsertAfter ("]")

End If

Next I

Next Nparag

End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.