|
-
Sep 19th, 2001, 08:32 AM
#1
Thread Starter
Hyperactive Member
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.
-
Sep 19th, 2001, 11:08 AM
#2
Fanatic Member
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:
Dim wo As Word.Application
Dim wd As Word.Document
On Error Resume Next
Set wo = GetObject(, "Word.Application")
If Err.Number <> 0 Then
' if word isn't open, then open it
Set wo = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo WordError
' make visible and add new document
wo.Visible = True
wo.Documents.Add "normal.dot", , , True
' get document reference
Set wd = wo.ActiveDocument
'
' do your work here - read that TXT file.....copy it to clipboard
'
' insert data into the document
wd.Range.Paste
' ask user if they want save it and then close Word
'wo.Quit wdPromptToSaveChanges
Set wo = Nothing
Set wd = Nothing
Exit Sub
WordError:
Err.Clear
MsgBox "Word not running"
Set wo = Nothing
-
Sep 19th, 2001, 11:13 AM
#3
Fanatic Member
PS: If you use 'InsertAfter', then you have to deal with setting fonts and such before the insert.
-
Sep 19th, 2001, 12:11 PM
#4
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|