Results 1 to 5 of 5

Thread: Ms Word Automation Via Vb

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    5

    Angry

    I have a problem in a system I am designing at the moment. It requires all correspondense between the customer and the clients to be stored somewhere. The majority of this will involve Ms word documents and Emails. I would like some way to control what they can do in word and also control where the documents are saved so I can log this in my database and reopen the documents from my program when requested.

    Any other idea's or soloutions on this or another theme would be greatly apreciated.

    Thanks in Advance

    Jamie Brown


    [Edited by Brown on 11-09-2000 at 06:36 AM]

  2. #2
    Fanatic Member Gaffer's Avatar
    Join Date
    Nov 2000
    Location
    London
    Posts
    828
    The key to this is making Word an object in your Program. This is done in two ways, by CreateObject or GetObject. The online help in Access97 or VB give good examples, or search microsoft.com for office automation.

    Basically, use CreateObject of you need to start Word from scratch, use getObject if Word is already open.

    Eg
    Code:
     Dim objWord As Object
    
    Set objWord = CreateObject("Word.Application")
    
    objWord.Visible = True
    
    With objWord
        'Code in Here
    End With
    It also helps if you add the Word reference library, as you will be able to use the Word VBA help screens

    Hope this helps

  3. #3
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008

    Exclamation

    gaffer, Brown,

    If you can set a reference to the Word Object library then you would access Word with

    Code:
    Dim objWord As Word.Application
    Set objWord = New Word.Application
    ...
    This is not just a stylistic difference. This will be 'early-bound', i.e. VB 'knows' what kind of object it is dealing with. Using Create/GetObject() is 'late bound' - i.e. VB has to allow for any object. An early-bound call to an object property can be two hundred times faster than a late-bound call.


    Cheers,

    Paul.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  4. #4
    Fanatic Member Gaffer's Avatar
    Join Date
    Nov 2000
    Location
    London
    Posts
    828
    Brown,

    Apologies, Paul is more on the ball than me this morning!

    Of course this is just the start of the whole catacomb of Office automation, and I would still check out the Microsoft site or the excellent Sybex range of books. I seem to recall that most of the help screen advice is centred toward Excel automation, so you may need to dig around for the Word related stuff.
    Aneasy way to start is by recording a macro in word, emulate the process you want to automate, and then cut, paste, and adapt the resultant code into your VB project:

    eg

    Code:
    With objWord
        .Documents.Open FileName:="c:\MyDoc.doc"
        .Selection.MoveDown Unit:=wdLine, Count:=14
        .Selection.MoveUp Unit:=wdLine, Count:=1
        .Selection.TypeText Text:="This is added Text!"
        .ActiveDocument.Close
    End With
    (This opens a doc, adds text, and closes)

  5. #5
    Hyperactive Member Jupiter-SL9's Avatar
    Join Date
    Apr 2001
    Location
    Porto Alegre
    Posts
    289

    Question inserting a table in microsoft word doc

    Hi
    To insert text, it´s ok, but how can i insert a table by code in vb???

    daniel
    If you want to be loved, first love who God gave to you.

    "Se você quer ser amado, primeiro ame quem Deus te deu"

    (Acts 20:35)

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