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

Pre-populating a Word Table from Excel

Status
Not open for further replies.

AshleyHolmes

Technical User
Jan 2, 2003
4
GB
I have a word template that I would like to have pre-populate certain cells in a word table from an existing excel spreadsheet when it is opened.

Any pointers would really be appreciated.

Many thanks.
 



Hi,

Maybe an example would be helpful, so we don't have to guess what you're working with.

What does you Excel source data look like? Is it a table or random cells?

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Thanks, but I did the following in the end. Basically I selected the value from an Excell cell into a variable and then inserting the value into word using a bookmark.

Their is probably a better way of doing it but I'm a Unix boy by trade and not that good with this Microsoft stuff. I would have preferred to put the whole table in an array. Is that possible?

' Create a Excel application object
Set ExcelObj = CreateObject("Excel.Application")

' Open a spreadsheet detailed in testbox4 into this object
ExcelObj.Workbooks.Open (TextBox4.Value)

' Get a values from the spreadsheet
ReqEDRYear1 = ExcelObj.Worksheets("Results").Cells(2, 2).Value
ReqEDRYear2 = ExcelObj.Worksheets("Results").Cells(2, 3).Value
ReqEDRYear3 = ExcelObj.Worksheets("Results").Cells(2, 4).Value
SubsYear1 = ExcelObj.Worksheets("Results").Cells(3, 2).Value
SubsYear2 = ExcelObj.Worksheets("Results").Cells(3, 3).Value
SubsYear3 = ExcelObj.Worksheets("Results").Cells(3, 4).Value

' Print the values to bookmarks
With ActiveDocument
.Bookmarks("ReqEDRYear1").Range.InsertAfter ReqEDRYear1
.Bookmarks("ReqEDRYear2").Range.InsertAfter ReqEDRYear2
.Bookmarks("ReqEDRYear3").Range.InsertAfter ReqEDRYear3
.Bookmarks("SubsYear1").Range.InsertAfter SubsYear1
.Bookmarks("SubsYear2").Range.InsertAfter SubsYear2
.Bookmarks("SubsYear3").Range.InsertAfter SubsYear3
End With

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top