Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   Transferring Information - EXCEL > WORD (http://www.go4expert.com/forums/transferring-information-excel-word-t15391/)

IcePirate 4Dec2008 01:45

Transferring Information - EXCEL > WORD
(Code is below)

Hello, I have a script that will open a word document based on the data I put in row 1 in excel up to column "E"

Then in "Column F" there is a button that says "Create document" and iwhen you click it, the button triggers Word to open; and create a word document based on row1 of whats in your Excel document

My problem is what about rows 2, 3, 4, and so on and so on...I want that "Create document" button to be listed on every rows in column "F" and when the button is clicked the script to build a word document based on only the information in that row the button is clicked for
<Tim> <26> <Coral St. > "<Create Document>"
<Jim> <Knows> <Red-Deer Rd.> "<Create Document>"

My code is below...I cant seem to determine what I should add to the script to have a command button on every row and how to only get it to trigger and make a word document for the information only on that specific row (any help is appreciated!!)


Option Explicit
Public Sub TransferData()
'This macro transfers the data range "A1:E1" to a table in Word
'docFullName = The full name of an already existing Word document
'doc = The Word document (assumed to be empty)
'i = A counter (for rows)
'j = A counter (for columns)
'tbl = A Word table
'wdRng = A Word range (the first paragraph of doc)
'wks = The worksheet "data" that contains the data range
'Const docFullName = "C:\OLE Automation\Word.doc" '
Dim doc As Object
Dim i As Long
Dim j As Long
Dim tbl As Object
Dim wdApp As Object 'Only if you require a new document each time
Dim wdRng As Object
Dim wks As Worksheet

'Assing Word objects 'Only if you require a new document each time
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True
Set doc = wdApp.Documents.Add

'Assign variables and objects
'Set doc = GetObject(docFullName) 'Only if you want a specific document
Set wdRng = doc.Paragraphs(1).Range
Set tbl = doc.Tables.Add(wdRng, 11, 5)
Set wks = ThisWorkbook.Worksheets("Transmittal")

'Transfer the data
With tbl
For i = 1 To 1
For j = 1 To 5
.Cell(i, j) = wks.Cells(i, j)
Next j
Next i
End With

'Save and close doc 'Only if you want a specific document
'Call doc.Save
'Call doc.Close(False)

Set doc = Nothing
Set wks = Nothing

End Sub

Private Sub CommandButton2_Click()

End Sub

shabbir 4Dec2008 09:07

Re: Transferring Information - EXCEL > WORD
Duplicate of Transferring Information - EXCEL > WORD. Thread closed.

All times are GMT +5.5. The time now is 23:25.