to input data from excel file

C

crazyfisher

Dear all

I am trying to generate some notification letters to a list of patients.
just a problem, if the patient name and address information is in the excel
file, how should I input them via macro to the word?



VBA:
Option Explicit
Dim D As Word.Document
Dim R As Word.Range
Dim x, inpTitle, inpFirstName, inpClient, inpSurName, inpAddress, inpSuburb,
R1
Sub printletter()
Selection.HomeKey unit:=wdStory
'pay attention to the format and space out the commands
'vbcrlf--visual basic carriage return line feed
Open "E:\patient.xls" For Input As #1
Do
' show the sequence of all types of data
Input #1, inpTitle, inpFirstName, inpSurName, inpAddress, inpSuburb,
inpTime

Set D = Documents.Add("E:\patient.dot")
Set R = D.Bookmarks("address").Range

R.InsertAfter inpTitle & " " & inpFirstName & " " & inpSurName &
vbCrLf
R.InsertAfter inpAddress & vbCrLf
R.InsertAfter inpSuburb

ActiveDocument.Bookmarks("date").Select
Selection.TypeText Format(Date, "dd/mm/yy")

'ActiveDocument.Bookmarks("name").Select
'Selection.TypeText inpTitle & " " & inputSurName

Set R1 = D.Bookmarks("name").Range
R1.InsertAfter inpTitle & " " & inpSurName


'create more docs with the data.
x = x + 1
D.SaveAs ("E:\letter" & x & ".doc")
D.Close savechanges:=wdDoNotSaveChanges
Loop Until EOF(1)
Close #1
End
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