Fill a word form clicking on an excel cell

D

Denis

Hi all,
I would like to be able to fill a word form from an excel sheet by clicking
on a cell and transferring the data from the different cells of the row in a
word document.
example :
Excel sheet :
Name1 address1 code1 city1
Name2 address2 code2 city2

I click on the cell Name1 and may be active a macro or a specific button to
get my word document filled with the information.

I know how to insert cells into a word document, but I would like to have an
automation when I click on a row or on a cell.
I'm not aware about programming so it could be great if the solution was
very easy to set up.
Thanks a lot
 
M

macropod

Hi Denis,

You could use a SelectionChange event-driven macro attached to the relevant worksheet. The following example populates an array with
the contents of columns A:D for the current row if any of the cells in A1:A10 is selected. It then outputs those values via a
message box.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Integer
Dim MyStr(3)
If Intersect(Target, ActiveSheet.Range("A1:A10")) Is Nothing Then Exit Sub
For i = 0 To 3
MyStr(i) = Target.Cells(1, i + 1).Value
Next
MsgBox Join(MyStr(), vbCrLf)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top