Saturday, 5 May 2018

MS Office Word - copy text and it puts OLE bookmarks - a handy macro to stop this

Have you recently found that copying something in Microsoft Word causes the copied text to have grey square brackets surround it?

These brackets are showing because the "show bookmarks" option is enabled. Indeed you may want to keep that option enabled, as you have other bookmarks that you want to see while editing.

The new bookmarks are being created with a certain naming format, they are sequentially numbered and are named like "OLE_LINK##". These bookmarks are automatically created by Word.

Here is a macro to automatically delete the bookmarks straight after they're created. It doesn't delete other bookmarks, only the ones that start with "OLE_LINK".

The best place to put this is in the file. To find this, enable the Developer tab in the ribbon, and then click on the Visual Basic button. In there you can find a file called "ThisDocument" inside the "Normal" heading. Inside that file just put the following code and then save it.

Sub EditCopy()
    Application.OnTime Now + TimeValue("00:00:01"), "DeleteOleBookmarks"
End Sub

Sub DeleteOleBookmarks()
    Dim bmIndex As Integer
    Dim bmType As String
    For bmIndex = ActiveDocument.Bookmarks.Count To 1 Step -1
        bmType = UCase(Left(ActiveDocument.Bookmarks(bmIndex).Name, 8))
        If bmType = "OLE_LINK" Then
        End If
    Next bmIndex
End Sub

No comments:

Post a Comment