cupper
asked on
Writing to an MS word document from VB
I am trying to write to an MS Word document by repeatedly copying something to the clipboard and pasting it to an open Word document. I am using the following
Dim msWord As New Word.Application
Dim msWordDoc As New Word.Document
On Error Resume Next
Set msWord = GetObject(, "Word.Application") 'look for a running copy of Excel
'
If Err.Number <> 0 Then 'If Excel is not running then
Set msWord = CreateObject("Word.Applica tion") 'run it
End If
msWord.Visible = True
Set msWordDoc = msWord.Documents.Open(file info.WordF ile)
<Copy something to clipboard>
msWordDoc.Content.Paste
<Copy something to clipboard>
msWordDoc.Content.Paste
<Copy something to clipboard>
msWordDoc.Content.Paste
The trouble is that everytime I paste, it just replaces the previous image. I haven't used MS word in VB before.
Any suggestions?
Dim msWord As New Word.Application
Dim msWordDoc As New Word.Document
On Error Resume Next
Set msWord = GetObject(, "Word.Application") 'look for a running copy of Excel
'
If Err.Number <> 0 Then 'If Excel is not running then
Set msWord = CreateObject("Word.Applica
End If
msWord.Visible = True
Set msWordDoc = msWord.Documents.Open(file
<Copy something to clipboard>
msWordDoc.Content.Paste
<Copy something to clipboard>
msWordDoc.Content.Paste
<Copy something to clipboard>
msWordDoc.Content.Paste
The trouble is that everytime I paste, it just replaces the previous image. I haven't used MS word in VB before.
Any suggestions?
there's a "range" thing you have to set to the end of the text you just inserted, I think is your problem
ASKER
Could you be more specific.
ASKER
Could you be more specific.
ASKER
Could you be more specific.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim mydoc as Word.Document
set mydoc = new Word.Document
mydoc.Range.Paste
mydoc.SaveAs "c:/temp/Mydoc.doc"
mydoc.Close
set mydoc = nothing
set mydoc = new Word.Document
mydoc.Range.Paste
mydoc.SaveAs "c:/temp/Mydoc.doc"
mydoc.Close
set mydoc = nothing
ASKER
Richie,
Thank you much for your help! An extra 25 points for your timely response.
cupper
Thank you much for your help! An extra 25 points for your timely response.
cupper
You are welcome and thanks for "A" grade and extra points!!