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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting data out of XL worksheet embedded in Word

Status
Not open for further replies.

ungarata

Technical User
May 5, 2008
1
US
hello all;

i'm pretty much a VBA newbie, but here's my question: if i embed an XL worksheet into Word as a table, how can i get particular cell data out of it to be used by my VBA code? for instance, say i have an XL worksheet in Word with lots of very detailed data in it, and i want to pull out specific cell data (text) and use it to make a small summary list in Word. i could do this by changing the value of a text label or text box, etc., that i have placed in Word. if it is a Word table, i can do this, but i can't get it to work if i drop an XL worksheet into Word. are there any code snippets or examples of this syntax?

thank you,

-ungarata
 
Use OLEFormat. Here's an example of inserting text into embedded excel worksheet (for inline object, assumed reference to excel library):
Code:
Sub GetEmbeddedExcel()
Dim wdOLF As Word.OLEFormat
Dim xlWbk As Excel.Workbook
Dim xlWks As Excel.Worksheet

Set wdOLF = ThisDocument.InlineShapes(1).OLEFormat
With wdOLF
    .DoVerb VerbIndex:=wdOLEVerbHide
    Set xlWbk = .Object
    Set xlWks = xlWbk.Worksheets(1)
    xlWks.Range("A1") = "text inserted by code"
End With
End Sub

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top