Edit Word doc programmatically?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Edit Word doc programmatically?

  1. #1
    Pritchard Guest

    Edit Word doc programmatically?


    I know I can easily open an MS Word document from within VB, but how can I
    edit that document programmatically?

    For Example:

    Say I have a commonly used worksheet protocol saved as a word document.
    Iíd like to be able to create several instances of that document from within
    a VB app and customize some of the contents (as in label captions, if I can
    figure out how to use them effectively in a word doc) based on specific data
    from a database before printing them.

    As Iím tinkering with this, I can find quite a bit of information on accessing
    various documents, but having a little trouble finding much about actually
    manipulating them programmatically.

    Thanks in advance for any help you can offer.


  2. #2
    Kenny Acock Guest

    Re: Edit Word doc programmatically?


    Pritchard,

    >I know I can easily open an MS Word document from within VB, but how can

    I
    >edit that document programmatically?


    You can "cheat":

    Create a macro in Word that does what you want to recreate in VB. Then open
    the macro in Visual Basic for Apps and look at the code it generated. This
    should at least get you started in the right direction.


    --Kenny

  3. #3
    Pritchard Guest

    Re: Edit Word doc programmatically?


    Thanks... I'll give it a shot.

    I typically avoid trying to work within the Word doc itself because I can
    never seem to place my labels where I need them, especially if my document
    is a compilation of lines and shapes.




  4. #4
    Pritchard Guest

    Re: Edit Word doc programmatically?


    I must not be too adept with macros... Iíve created one to do what Iíd like...
    but I canít find anything to open in VB.

    >Create a macro in Word that does what you want to recreate in VB. Then

    open
    >the macro in Visual Basic for Apps and look at the code it generated. This
    >should at least get you started in the right direction.




  5. #5
    Arthur Wood Guest

    Re: Edit Word doc programmatically?


    Pritchard,
    In Word, pull down the Tools menu, towards the bottom of the pull down
    menu, you wil find Macro> select thwe Macro item, then go to Macros...
    That will open the Macro Dialog box. YOu should see a Macro1 listed, select
    it, then click on the Edit button. That will open the Macro in the Visual
    Basic Editor which is built into Word (You are now using Visual Basic for
    Applications (VBA)).

    Arthur Wood


    "Pritchard" <dprit@pacbell.net> wrote:
    >
    >I must not be too adept with macros... Iíve created one to do what Iíd like...
    >but I canít find anything to open in VB.
    >
    >>Create a macro in Word that does what you want to recreate in VB. Then

    >open
    >>the macro in Visual Basic for Apps and look at the code it generated.

    This
    >>should at least get you started in the right direction.

    >
    >



  6. #6
    Dean Earley Guest

    Re: Edit Word doc programmatically?

    The Easiest way to access word documents in VB is to add a reference to Word
    Object in Project references.

    Dim WordApp as Word.Application
    Dim Doc as Word.Document

    set WordApp = CreateObject ("Word.Application")
    Set Doc=WordApp.Documents.New

    Or something along those lines

    --
    Dean Earley (dean.earley@icode.co.uk)
    Assistant Developer

    iCode Systems
    "Pritchard" <dprit@pacbell.net> wrote in message
    news:3a845025$1@news.devx.com...
    >
    > I know I can easily open an MS Word document from within VB, but how can I
    > edit that document programmatically?
    >
    > For Example:
    >
    > Say I have a commonly used worksheet protocol saved as a word document.
    > I'd like to be able to create several instances of that document from

    within
    > a VB app and customize some of the contents (as in label captions, if I

    can
    > figure out how to use them effectively in a word doc) based on specific

    data
    > from a database before printing them.
    >
    > As I'm tinkering with this, I can find quite a bit of information on

    accessing
    > various documents, but having a little trouble finding much about actually
    > manipulating them programmatically.
    >
    > Thanks in advance for any help you can offer.
    >




  7. #7
    Kenny Acock Guest

    Re: Edit Word doc programmatically?


    In MS Word go to Tools-->Macros-->Visual Basic Editor, or use the keyboard
    shortcut (Alt-F11). Your macros should be in one of the modules.

    --Kenny

    "Pritchard" <dprit@pacbell.net> wrote:
    >
    >I must not be too adept with macros... Iíve created one to do what Iíd like...
    >but I canít find anything to open in VB.
    >
    >>Create a macro in Word that does what you want to recreate in VB. Then

    >open
    >>the macro in Visual Basic for Apps and look at the code it generated.

    This
    >>should at least get you started in the right direction.

    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center