how to input from excel?

09/10/2007 - 05:39 von crazyfisher | Report spam
Dear all,

I want to input some contact information from excel to generate some
letters. how can I do that ? I know how to input from text file, however, it
doesn't work for excel.
this is my code:

Option Explicit
Dim D As Word.Document
Dim R As Word.Range
Dim x, inpTitle, inpFirstName, inpClient, inpSurName, inpAddress, inpSuburb,
inpTime, 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


ActiveDocument.Bookmarks("time").Select
Selection.TypeText inpTime

'insert into the signature
ActiveDocument.Bookmarks("sign").Select
Selection.InlineShapes.AddPicture FileName:="E:\sign.jpg",
LinkToFile:=False, SaveWithDocument:=True

'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
 

Lesen sie die antworten

#1 Helmut Weber
09/10/2007 - 13:26 | Warnen spam
Hi Crazyfisher,

see:
http://word.mvps.org/faqs/interdev/...omword.htm
plus
http://word.mvps.org/faqs/interdev/...inding.htm

"input" is not suitable for files,
the binary or bytewise structure of which is unknown to you.

by the way, you posted this to a german speaking group.

Try
microsoft.public.word.vba.general

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Ähnliche fragen