The spell id has nothing to do with you spell book. It's just a unique number for every spell in wow. The spell id of a given spell is the same for every player on every realm.
This is my code to get the spell link and the spell id out of the spell link:
Code:
local spellLink = GetSpellLink(name, rank)
local spellID = string.sub(spellLink, 19, string.find(spellLink, "%[") -3)
Don't know if the spell id can be used in macros.
btw: don't know what you're about to do, but there are approximately 25.000 spells/spell id's.