Results 1 to 4 of 4

Thread: Need help w/ Microsoft Word 9.0 Object Library

  1. #1

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391

    Need help w/ Microsoft Word 9.0 Object Library

    Alright, I managed to create instances of Word.Application and Word.Document. It was either a licensing or version problem ( I installed Word 2000 and it worked).

    So now I need help with document manipulation. Before I do anything, I read a TXT file and store its contents into the clipboard.

    Once that is done, I open up my instances of Word.Application and Word.Document. No problem there, I set them visible and give them focus. What I am looking for now is a way to insert the contents of the clipboard into the document. (The document BTW will already contain a graphical header)

    I'm sure this would be possible using SendKeys, but I find that SendKeys is slow and unreliable.(Too many uncertainties, too many things can go wrong).

    I looked through the methods and properties of Word.Document but didn't find anything pertaining to editing the textual contents of the file. Is there something I'm missing, or some poorly named method that does what I'm looking for? I saw a method called SetLetterContent and thought this might be useful.

    I know I can declare an instance of class LetterContent, but what is LetterContent, and what does it contain? Am I on the right track?

    If anyone has any insight on this I would appreciate it greatly, Thanks.

  2. #2
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    If the data is already in the clipboard....just paste it to the document with the code below. If you need to paste in a certain area, I'm at a loss there....never had to deal with modifying documents.

    If you need more control of inserting data in that document, look at the InsertAfter method of the document.

    ie: wd.Range.InsertAfter ("your text here")

    VB Code:
    1. Dim wo As Word.Application
    2. Dim wd As Word.Document
    3.  
    4.     On Error Resume Next
    5.     Set wo = GetObject(, "Word.Application")
    6.     If Err.Number <> 0 Then
    7.         ' if word isn't open, then open it
    8.         Set wo = CreateObject("Word.Application")
    9.     End If
    10.     Err.Clear
    11.     On Error GoTo WordError
    12.    
    13.     ' make visible and add new document
    14.     wo.Visible = True
    15.     wo.Documents.Add "normal.dot", , , True
    16.    
    17.     ' get document reference
    18.     Set wd = wo.ActiveDocument
    19.    
    20.     '
    21.     ' do your work here - read that TXT file.....copy it to clipboard
    22.     '
    23.  
    24.     ' insert data into the document
    25.     wd.Range.Paste
    26.    
    27.     ' ask user if they want save it and then close Word
    28.     'wo.Quit wdPromptToSaveChanges
    29.    
    30.     Set wo = Nothing
    31.     Set wd = Nothing
    32.     Exit Sub
    33.    
    34. WordError:
    35.     Err.Clear
    36.     MsgBox "Word not running"
    37.     Set wo = Nothing

  3. #3
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    PS: If you use 'InsertAfter', then you have to deal with setting fonts and such before the insert.

  4. #4

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Range.Paste! Aha! That is just what I was looking for! Thank you very much =)

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