Use VBA to integrate Excel data into Word document through VLookup function

mnetzel

New Member
Joined
Jun 29, 2017
Messages
1
Hello,

I am trying to pull data from multiple Excel 2013 workbooks into a Word 2013 document that I cannot simply copy and paste a link from Excel into Word. I tried researching this on other articles and threads, but they seem to only include portions of what I am looking to accomplish, so please excuse if the code appears messy or contradictory.

What I am looking to do is enter a customer ID (sellerID) into an input box, which would be the 'lookup_value' in the VLookup function. The 'Model' workbook and 'Parent' worksheet is where the 'table_array' is located. I have inserted ActiveX labels into the Word document where I would like the data to appear. In the code below, I want the VLookup to find the customer's region and insert into the 'Region' label.

I am getting a 1004 Error - Unable to get the VLookup property of the WorksheetFunction class. I used the object browser and it looks like the Excel.Application.WorksheetFunction.VLookup are the correct classes. What am I missing?

Code:
Private Sub CommandButton1_Click()
Dim objExcel As New Excel.Application
Dim exModel As Excel.Workbook
Dim wkshtParent As Excel.WorksheetDim sellerID As String

    sellerID = InputBox("Please enter the Seller ID", "Input")
    Set exModel = GetObject("R:\05-2017 Model.xlsx")
    Set wkshtParent = exModel.Worksheets("Parent")
   
    ThisDocument.Region.Caption = objExcel.WorksheetFunction.VLookup(sellerID, wkshtParent.Range("B:G"), 4, False)
    
    exModel.Close
    
    Set exModel = Nothing

End Sub

Please advise. Any feedback on how to clean up the code or make the process more efficient is welcomed, as well.

Thank you!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top