CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2000
    Location
    Rotterdam, Netherlands
    Posts
    115

    Creating Word documents from within VB

    Hi there,

    I 'd like to know if it is possible to create a word document from within Visual Basic, without starting MS Word itself, e.g. by using the Word Object library?!?

    I want to create a new document, put text in it, not displaying any of this to the user and then save it to a .doc file.

    Please help!

    greetz Law



  2. #2
    Join Date
    Aug 2000
    Location
    England
    Posts
    185

    Re: Creating Word documents from within VB

    Hello,

    The only way I know of is to create a series of rtf statements and then write them to a file with a .doc extension. The file will then load.

    The big problem is that rtf files are extremely difficult to create manually. My advice to you would be to create a blank rtf document to use as a template, which will contain all of the start and end information. Each new line in the document must start with a /par statement but I advise you to read up on the subject if you wish to do anything more complex as some of the commands are arcane to say the least.

    Once you have the statements stored in the array or whatever it is simply necessary to write them in the same order as they were created to the .doc file. All the new statements should be inserted before the last one as this closes the document.

    Hope this helps

    Andrew


  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Creating Word documents from within VB

    Actually, A .rtf file can be easily be created using the RichTextBox control.
    Just enter your text and images into it and then use its SaveFile method. It will create all the Html stuff for you.

    John G

  4. #4
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Creating Word documents from within VB

    Here is one example already posted in this forum. You might search this forum for other examples.
    I found this one by going to "SEARCH' keying in "Word Document" and hitting the search button.
    '
    http://63.236.73.79/cgi-bin/bbs/wt/s...age=0&Limit=25

    John G

  5. #5
    Join Date
    May 2001
    Posts
    155

    Re: Creating Word documents from within VB

    Try this:
    First go under project | References, and check Microsoft Scripting Runtime (scrrun.dll)

    Dim tex as Filesystemobject
    Dim b
    b = Freefile
    set tex = new Filesystemobject
    tex.createtextfile "C:\My Documents\mydocfile.doc"
    Open "C:\My Documents\mydocfile.doc" for output as b
    print #b, mytext.text
    Close b



    HTH

    --Ant
    --------------------------------------------------
    check out my newest freeware
    E-mail me at: [email protected]
    for the address

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