none
Type Text in Word from Access VBA

    Question

  • Hi

    I'm a novice in using Access VBA to do things in Word and would like some code that will type into word. I have the following as a starting point and although it runs through without error, I cannot see the text in the resulting Word doc. What am I doing wrong? Thanks in advance.

    Dim MyWord As Word.Application, MyDoc As Word.Document, MySelection As Selection

    Set MyWord = New Word.Application
    Set MyDoc = MyWord.Documents.Add
    Set MySelection = Word.Selection

    MyWord.Visible = True

    MySelection.TypeText ("Project Status Report")
    MySelection.TypeParagraph

    End Sub

    • Moved by Jeff Shan Friday, October 30, 2009 1:19 AM vba question (From:Visual Basic General)
    Wednesday, October 28, 2009 5:17 PM

Answers

  • Hello,

    After the document is added, please make sure it's active document of Word:

    MyDoc.Activate

    OR

    Use Range.Text property to input text, like:
    MyDoc.Range(0.0).Text="My Input"

    Thanks.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Tim Li Tuesday, November 03, 2009 6:09 AM
    Tuesday, November 03, 2009 6:09 AM

All replies