Hi,
I have a table in MS Word and i want when users type in #80282 in one of the
cell in the table (in MS Word), it will look up my excel file for that code
and have the details about that code (like product ID, price etc) added
automatically into my Word's table.
Is that possible?
in a way, yes.
But there is more to it than meets the eye.
Can you control Excel from Word?
If not, see:
http://word.mvps.org/faqs/interdev/controlxlfromword.htm
You cannot, at least not with justifiable effort,
have Word react on each key pressed.
You can react on a tab pressed, if the insertion point is in a table.
For that you overwrite the built in command "nextcell".
With doing that, you got to have a replacement for NextCell:
Wordbasic.NextCell.
As pressing tab in the last cell of a table
results in a new row added, you'd have to check before,
whether the insertion point is in the last cell.
And there is a hell of more complications.
like you have to restrict that to a specific table.
Sub NextCell()
Dim C1 As Long
Dim C2 As Long
Dim rTbl As Range
Set rTbl = Selection.Range
C1 = Selection.Tables(1).Range.Cells.Count
rTbl.Start = Selection.Tables(1).Range.Start
rTbl.End = Selection.End + 1
C2 = rTbl.Cells.Count
If C2 < C1 Then
WordBasic.NextCell
' collect data from Excel <<<<
MsgBox "here comes the Excel part"
' but not for the last cell in the table
End If
End Sub
--
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"