Tahir Hassan's Blog

My Technical Notes

Wednesday, 18 March 2015

Inserting an OpenOffice Draw diagram into an MS Word document

I am using MS Office 2010 and OpenOffice 4.1.1.

Let's say you are storing all your files in a folder named `dissertation`. This folder has the following structure:

  • `dissertation` - the containing folder for all dissertation-related documents.
    • `dissertation.docx` - the Word 2010 document.
    • `tools_diagram.odg` - the Draw document
    • `exports` - a folder containing all exported diagrams.
      • `tools_diagram.emf` - The above diagram's export in EMF format (Enhanced Meta File).

Within `tools_diagram.odg`, set all the margins to zero.

The first step is to export `tools_diagram.odg` to an `.emf` file:

  • Click on `File` → `Export`, set the path to be in `exports` folder, `Save as type` = `EMF` and accept the default options and click `OK`.

Next, within your Word document, you use `Ctrl+F9` to insert a field code bracket, and within it type:

Thereafter, press `F9`. Use `Alt+F9` to toggle the field codes so you can see your diagram. You may have to resize the diagram.

MS Word 2010 - Inserting image with relative path

To insert an image with a relative path, we first use `Ctrl+F9` to insert field code brackets. Within the brackets, we want the following code:

Note that if you are using a back-slash in the path, you will need to double them up, to escape them.

Alternatively, you can use forward slashes instead, which do not need escaping:

In MS Word, fields don't automatically update, therefore you will need to press `F9` while caret is inside it.

`Alt+F9` toggles field codes in the document.

SVN - Branching and Merging


To work on a separate branch, we use `TortoiseSVN` → `Branch/tag...` on the trunk directory.

  • In the `To URL`, we specify the path to the branch directory, `.../branches/my_branch`.
  • Tick `Switch working copy to new branch/tag`.

At this point, our trunk is a working copy of `branches/my_branch`. We make all the changes we need to `my_branch` and check them in. Once we are satisfied, we have to merge the changes back into the trunk.


To merge the changes:

  • Switch working copy back to trunk. (SVN will remove all the changes you made, so the directory will look just like found on the SVN server.)
  • Now select `TortoiseSVN` → `Merge...`. Select `Reintegrate a branch`. In the `From URL`, we specify the full path to `branches/my_branch`. Click `Next` and then `Merge`. Once the merge is over, your trunk directory will look like your `my_branch` directory.
  • Finally, check-in all your changes as you would normally, to your trunk.

Tuesday, 10 March 2015

Updating all fields in Word document

The following code works in Word 2010:

Saturday, 7 March 2015

A PowerShell Wrapper around Subst

Below is a wrapper module for the `subst` command found on the normal cmd shell. We define three functions following the Verb-SingularNoun pattern where the noun is `Subst`. A `subst` is a drive mapping (a "substitution").

  • `Get-Subst` - returns objects representing each drive mapping made with `subst`.
  • `New-Subst` - make a new drive mapping. It has a switch called `AutoAssignDrive`, so we don't have to provide a drive letter - it will automatically assign one for us.
  • `Remove-Subst` - remove an existing drive mapping.

Friday, 6 March 2015

Windows 7 - making networked drives work under administrator account

To the following Registry key:

add a new DWORD entry with the name `EnableLinkedConnections` and value `1`.

Getting all function names in a PowerShell module using C#

The following code gives all the module names within a powershell module. It uses the `System.Management.Automation` DLL found in

Here is the code: