Results 1 to 5 of 5

Thread: How to use Microsoft Word from within VB?

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 1999
    Location
    dubai
    Posts
    39
    Hello!


    I want to open a word doc from VB and put some text and save it. Can anybody tell me how this can be achieved?



    Thanks,
    ganraj.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    'not sure how you want to do it
    'here is one way
    'you can shell word and then put your stuff in and save on
    close


    Private Sub Command1_Click()
    Shell "C:\Program Files\Microsoft Office\Office\WINWORD.EXE", 1

    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Addicted Member
    Join Date
    Jan 2000
    Location
    Fresno, California, USA
    Posts
    195
    Here is some code I've saved from previous answers to questions here:

    Dim WordApp As Word.Application
    Dim WordRange As Word.Range
    Dim nCount As Integer: Dim x As Integer
    Dim nlRangeStart As Long

    'Starting Word
    Set WordApp = New Word.Application
    WordApp.Application.Visible = True
    WordApp.Documents.Add
    Set WordRange = WordApp.ActiveDocument.Range
    WordRange.Font.Size = 22
    WordRange.InsertAfter "1-Name" & vbCrLf
    WordRange.InsertAfter "2-Address" & vbCrLf
    WordRange.InsertAfter "3-City" & vbCrLf
    For x = 1 To 5
    WordRange.InsertAfter " " & vbCrLf 'empty line
    Next x

    WordApp.ActiveDocument.SaveAs ("Path and Filename")
    WordApp.Documents.Close (wdDoNotSaveChanges)
    WordApp.Quit
    Set WordApp = Nothing

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 1999
    Location
    dubai
    Posts
    39

    Talking

    Thanks Guys for your reply



    Ganraj
    ganraj.

  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    <¿>

    does it need to be a word doc?

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