Results 1 to 13 of 13

Thread: Writing Word document with VB6

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Location
    Ocean Park, WA USA
    Posts
    9

    Writing Word document with VB6

    I am writing a VB6 application that writes to a Word 2000 document. I want to control when a new page is added to the document and set the template the new page will use. There is no user interface while the document is being written by VB. Logic in the application is writing the document.
    Comments please.

  2. #2
    Addicted Member
    Join Date
    Jul 2001
    Posts
    133
    Word 2000 should have an Automation interface that can be accessed from VB.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Location
    Ocean Park, WA USA
    Posts
    9
    Yes it does have an automation interface, I have looked in the Word 2000 developer's handbook and VB help. I can find nothing that shows me how to control when a new page is added to a document or how to attach a template to the new page.

  4. #4
    Addicted Member
    Join Date
    Jul 2001
    Posts
    133
    OK. So your saying that you want VB6 to capture what Word is up to? I thought that you were completelly contolling the situation through VB6. In your case, It sounds like you are saying that Word is running on it's own and you want to intercept activities?

    Perhaps, you need to write VB Script WITHIN WORD.

  5. #5
    Fanatic Member skald2k's Avatar
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    535
    Either a script or a macro will do the job.
    - If at first you dont succeed, then give up, cause you will never will!

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Location
    Ocean Park, WA USA
    Posts
    9
    VB is controlling the word object and writing to the document. The output of several modules is writing to the document. This is a Computer Aided Process Planning application for manufacturing. It is a generative process not a variant.

  7. #7
    Addicted Member
    Join Date
    Jul 2001
    Posts
    133
    If Word is controlling the object, do you not already know when a new page is being added (afterall, you - VB - is doing it). And, if you know when your adding a page, can you not control the other necessary - the template?

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Location
    Ocean Park, WA USA
    Posts
    9
    I can find no available object, method, or property that will allow me to control when a new page is added. The PageSetup object & PageSetup property is available but they do not give me the ability to control when a new page is added or define the template. Thanks for your replies.

  9. #9
    Addicted Member
    Join Date
    Jul 2001
    Posts
    133
    You are prolly deeper into the Word Automation than the rest of us.

    Perhaps you can use RTF in VB than cause Word to import it when done?

  10. #10
    WorkHorse
    Guest
    MS Word VBA does support a Pages collection. You can use this to work with pages in a document. If you just want to add to the end of the document, it would be easier to move the selection there then put in a page break. You can insert a template using the insert method (as long you don't have the template open and try to insert the same template--Word won't allow that type of recursive error). Here's the VBA code:

    VB Code:
    1. With Selection
    2.         .EndKey Unit:=6 'wdStory
    3.         .InsertBreak Type:=7 'wdPageBreak
    4.         .InsertFile FileName:="C:\My Documents\MyTemplate.dot", Range:="", _
    5.         ConfirmConversions:=False, Link:=False, Attachment:=False
    6.     End With

  11. #11
    WorkHorse
    Guest
    Oh yeah, you don't have to do that in VBA. Just use your wdObj or whatever before the statements (or put the whole thing in a with statement) or create an object, etc., etc. and you can do it from VB.

  12. #12
    Addicted Member
    Join Date
    Jul 2001
    Posts
    133
    I thought I remembered that the Word object would do that!

    :-

  13. #13

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Location
    Ocean Park, WA USA
    Posts
    9
    Thank you for the help! I appreciate it.
    SurfsideRon

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