How to convert your footnotes and endnotes into compatible bookmarks

Lately I had a lot of trouble with one e-book. I had to format Microsoft word document to comply with standards. The biggest problem was to translate footnotes and endnotes into compatible cross referenced bookmarks/ links. 

 this is what you get if you have problems with Footnotes/Endnotes:

Footnote Error – Smashwords does not support automatic footnoting using Word’s footnoting field codes. If you need footnotes or endnotes, please use plain text in brackets, and then use Word’s “Bookmark” feature, described in the Smashwords Style Guide to create your hyperlinks to your footnotes and endnotes. For example, a paragraph could end with the following footnote… [234] (and then for your footnote or end note you could manually enter [234] followed by the footnote information.)

 Key tip is to put “ref_” in front of every bookmark if you do not want it to appear on the table of contents of your epub.

My book had ~500 endnotes. To do it by hand is a nightmare. To easy my pain i did two word macros – one inserts a bookmark and a link to the bookmark and the other one inserts a link back. (Unfortunately I inserted bookmarks next to endnotes by hand before I realized I need some macro). But is should not be to complex to modify my code to insert that bloody bookmark also.  Just look at the code and find out yourself which macro does what 🙂 So here is the code:

Sub BookamrkMagic()
x = Selection
Selection.MoveLeft Unit:=wdCharacter, Count:=2
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="ref_" + x
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", _
SubAddress:="ref_x_" + x, ScreenTip:="", TextToDisplay:=x
End Sub

Sub BookamrkMagicX()
x = Selection
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", _
SubAddress:="ref_" + x, ScreenTip:="", TextToDisplay:=x
End Sub

How to collect the same file from several different servers for comparison or other type of analysis :)

this example is also useful if you want to iterate through comma separated/delimited values stored in a variable in bat script
.bat file contents looks like this 🙂
@echo off

SET servers=server1,server2,

for /D %%f in (%servers%) do (
echo connecting to: %%f
net use \\%%f\c$\windows /delete
net use \\%%f\c$\windows /user:%%f\Administrator qwerty123.
copy \\%%f\c$\windows\log.log "%%f - log.log"
net use \\%%f\c$\windows /delete


Programmatically rejoin active directory domain after virtual machines snapshot is reverted

There is a problem with active directory computer accounts in combination with virtual machine snapshots. After virtual machine is added into domain computer account’s password gets updated in AD once in a while. In case you are coppying, moving, snapshoting or cloning machine which is joined to a domain you must have domain membership problems on those machines very often. It happens if password which is storred on your virtual machine and password on the account object in AD are out of sync. There are some administrative ways to fix that.

For example:

a) changing computer account password configuration policies in AD,

b) rejoining the domain by hand everytime domain membership is broken,

c) snapshoting not only virtual machine but Domain controller and restoring both snapshots in one atomic action

After I become tired of fixing those issues manually I decided to search for programmatic way to join the domain.

I wrote console application which is able to identify if the machine has broken domain membership and if it has it is able to fix it.

You can download the msi file here. download: FixDomainMembership.msi (450.5KB)
added: 22/05/2012
clicks: 436
description: Command Line Utility to fix domain membership

After the executable is installed on the machine with broken domain membership execute the command with command line parameter –help and follow the manual …