CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2001
    Posts
    17

    list box toword doc

    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


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: list box toword doc

    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
    [email protected]

    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
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Apr 2001
    Posts
    17

    Re: list box toword doc

    is this for embedded or linked document?
    Just for my general knowledge.


  4. #4
    Join Date
    Apr 2001
    Posts
    17

    Re: list box toword doc

    worked great thank you and it is a linked doc. no need to answer.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured