Click to See Complete Forum and Search --> : list box toword doc


leary
May 7th, 2001, 02:45 PM
Any ideas on how i an get the contents of listbox saved to a word document and have it saved as a seperate file each time for instance filename=date and time

Cakkie
May 8th, 2001, 02:28 AM
This code does the job, you just need to add a refference to word (Microsoft Word 8.0 Type library) via the Project>Refferences menu.
The list is called List1

' Declare a word application and document
Dim wApp as new Word.Application
Dim wDoc as Word.Document

' show word (you can omit this if you want this to happen in the background)
wApp.Visible = true

' add a new document
set wDoc = wApp.Documents.Add

' write the contents of the list to the document
for t = 0 to List1.ListCount - 1
wDoc.Range().InsertAfter List1.List(t) & vbCrLf
next t

' save the document
' eg "C:\20010508092812.doc"
wDoc.SaveAs "C:\" & Format(Now(), "YYYYMMDDHHNNSS") & ".doc"

' clean up
wDoc.Close
set wDoc = nothing

wApp.Quit
set wApp = nothing

' we're done




Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

leary
May 8th, 2001, 04:03 AM
is this for embedded or linked document?
Just for my general knowledge.

leary
May 8th, 2001, 04:18 AM
worked great thank you and it is a linked doc. no need to answer.