Getting late here and I am crap at VB anyway so will tell you what I do. I have a toolsetter at the side of my machine where I set up tools off the machine and it has an encoder on it which feeds into Mach. So its a manual process and not really what you want but here is how I get the info into the tooltable, this is the code in my button. You may be able to use parts of it in your macro, specifically the Code line and maybe look at your Z DRO instead of the encoder DRO that I look at..
If GetOemLED(800) Then
MsgBox ("Mach In Reset, Enable and start again")
End
End If
Offset = GetOemDRO(100) 'This is the Encoder DRO that height setter is connected to
SetOemDRO(1555,Question("Enter Offset Number"))
Tool = GetOemDRO(1555)
Code "G90" & "G10" & "L1" & "P" & Tool &"Z" & Offset
DoOemButton(121)
Hope this helps a bit, sleep time for me
Hood