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 Normal.dot 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()
    Selection.Copy
    DoEvents
    Application.OnTime Now + TimeValue("00:00:01"), "DeleteOleBookmarks"
End Sub

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

Tuesday 1 May 2018

Keep the monitor display brightness the same when the power source is changed to battery/charging

When using a laptop you usually have to adjust the screen's brightness based on the ambient lighting conditions. However, when plugging/unplugging the power supply Windows will change the brightness again. This can be a poor user experience, for example the reason for plugging it in was just to charge it, not to change the brightness.

Here is a PowerShell v3.0+ script and Windows Task Scheduler config file for fixing this issue. The schedule will run at system startup, and just runs the script. The PowerShell script will register a script block to some Windows events. One is the brightness change event, so when the user manually changes the screen brightness it will save that value to a temp file. The other event is when the power supply is changed to battery/charging, it will change the value back from the saved temp file.

Here's the PowerShell script, just copy this into a Notepad and save as "C:\Battery power display brightness.ps1".