PDA

View Full Version : Solved: linking with word



ashgull80
04-23-2012, 02:52 AM
hi
i was wondering if it is possible to link textboxes in a userform in excel to tables in a word document. i have read the thread which creates a table in word but i already have a sample document with tables that i need the data copied to a specific cell.
thanks
ash

snb
04-23-2012, 04:01 AM
Your information is rather 'limited'

If you want the value of cell F5 to be put into the first cell of the first table in the Word dcoument "G:\OF\example.doc" then use:


sub snb()
with getobject("G:\OF\example.doc")
.tables(1).cell(1,1).range.text=sheets(1).cells(5,6).value
.close -1
end with
end sub

ashgull80
04-23-2012, 04:24 AM
excelent works a treat, i changed the ceel to a userform text box and works perfect.
1 question though, how do i open the word document instead of closing it, can i also code it so it saves the word doc as a new file name?
thank you very much ash

snb
04-23-2012, 06:06 AM
Sub snb()
With getobject("G:\OF\example.doc")
.tables(1).cell(1,1).range.text=TextBox5.Text
.SaveAs "G:\OF\example 002.doc"
.close 0
End With
End Sub

ashgull80
04-23-2012, 06:22 AM
can i set the name for it to be saved as from a cell in table 1?

ashgull80
04-29-2012, 12:46 PM
Sub snb()
With getobject("G:\OF\example.doc")
.tables(1).cell(1,1).range.text=TextBox5.Text
.SaveAs "G:\OF\example 002.doc"
.close 0
End With
End Sub

gives me an error on

.tables(1).cell(1,1).range.text=TextBox5.Text

snb
04-29-2012, 01:54 PM
I have no idea what's in textbox5.
Please post your workbook.