Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Word and Excel linkage

Status
Not open for further replies.

sanjdhiman

Programmer
Jan 15, 2003
189
GB
Hi there I have a list of Address in Excel. What I need is a link between word and excel, so when the user via a combo box clicks on a surname, it automatically goes to the Excel sheet and grabs the relevant line of data and puts it into the form in word.. is this possible or am I living in a fantasy world?

I know its possible within say excel using the HLookup function or VLookup but is it possible in VBA and across two applications Word and Excel??

Kind regards

and thanks in advance

Sanj
 
Hi sanjdhiman,

Something like this ought to work:

Code:
Private Sub ComboBox1_Change()

Dim appXL As Excel.Application

Set appXL = CreateObject("Excel.Application")
appXL.Workbooks.Open "
Code:
C:\YourPath\YourWorkbook.xls
Code:
"
Code:
YourVariable
Code:
 = appXL.WorksheetFunction.VLookup(ComboBox1.Text, appXL.Range("
Code:
A1:B100
Code:
"), 2)

appXL.Quit
Set XL = Nothing

End Sub

You'll need a reference to the Excel library for it to work.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top