Results 1 to 2 of 2

Thread: Inserting text into word from VB

Hybrid View

  1. #1
    Junior Member
    Join Date
    Oct 03
    Posts
    31

    Inserting text into word from VB

    I'm wondering how to insert text into word using VB.

    I created a new word instantiation like this:

    Private wdCurrent As Word.Application

    Now I need to know what command I would use to insert text. Like...

    wdCurrent.????? = "text"

    What would fill in those question marks?

    Also, anyone know where I can find a list of commands for word? Like how to make text bold or italic.
    Last edited by Carter; Dec 17th, 2003 at 10:01 PM.

  2. #2
    PowerPoster
    Join Date
    Oct 02
    Location
    British Columbia
    Posts
    9,758
    If you have not already figured things out here is some sample code. Basically, all access to the contents of the document is through the Range object. A Range can be the entire document, a paragraph or a single word.

    Use the Object Browse (F2) to view all Objects, Methods and Properties that are available within the Word Library.

    VB Code:
    1. Dim objWord As Word.Application
    2. Dim objDoc As Word.Document
    3.  
    4. Set objWord = CreateObject("word.application")
    5. objWord.Visible = True
    6.  
    7. 'Creates a new document
    8. Set objDoc = objWord.Documents.Add
    9.  
    10. objDoc.Range.Text = "This is a test"
    11. objDoc.Range.Font.Bold = True
    12. objDoc.Range.Font.Italic = True
    13.  
    14. Set objDoc = Nothing
    15. Set objWord = Nothing

Posting Permissions

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