Results 1 to 2 of 2

Thread: text in VB ---> Word doc ?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904

    text in VB ---> Word doc ?

    I'm reasonably conversant w/ VB and VBA but I can't figure out how to do what I believe should be a simple operation which is to take a bunch of text and stuff it into MS Word (opening an instantiation of Word as part of the process). I can worry about formatting & stuff later, if someone can just push on my chest to get me breathing.

    Thanks for your time.

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Hi there phinds, here is a little sample for u

    VB Code:
    1. '----------------------------------------
    2. '- Name:    peet
    3. '- Email:   [email][email protected][/email]
    4. '- Web:
    5. '- Company: PvP
    6. '----------------------------------------
    7. '- Notes:   opens a word document using
    8. '       the MS Word object lib.
    9. '----------------------------------------
    10. Option Explicit
    11.  
    12. Private objWord As Word.Application
    13. Private wd As Word.Document
    14.  
    15. Private Sub Command1_Click()
    16.     Dim myRange As Range
    17.     Dim sSearchfor As String
    18.  
    19.     If objWord Is Nothing Then
    20.         Set objWord = CreateObject("Word.Application")
    21.     Else
    22.         Set objWord = GetObject(, "Word.Application")
    23.     End If
    24.     DoEvents
    25.     Set wd = objWord.Documents.Open("c:\Test.doc")
    26.     'here u can do stuff with the document
    27.     'using the wd object
    28.        
    29.     'adding some text to it
    30.     wd.ActiveWindow.Selection.TypeText "ABCDEFGH peet was here ! :-)"
    31.    
    32.     'when finished manipulating the document, u can show it To the user
    33.     objWord.Visible = True
    34.  
    35.     'quit word
    36.     If Not (wd Is Nothing) Then Set wd = Nothing
    37.     If Not (objWord Is Nothing) Then objWord.Application.Quit
    38.     If Not (objWord Is Nothing) Then Set objWord = Nothing
    39. End Sub

    hope this can get u off to a good start
    -= a peet post =-

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