Link to home
Start Free TrialLog in
Avatar of cupper
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.Application") 'run it
End If
   
msWord.Visible = True


Set msWordDoc = msWord.Documents.Open(fileinfo.WordFile)


<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?

Avatar of HobbitHouse
HobbitHouse

there's a "range" thing you have to set to the end of the text you just inserted, I think is your problem
Avatar of cupper

ASKER

Could you be more specific.
Avatar of cupper

ASKER

Could you be more specific.
Avatar of cupper

ASKER

Could you be more specific.
ASKER CERTIFIED SOLUTION
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dim mydoc as Word.Document

set mydoc = new Word.Document
mydoc.Range.Paste
mydoc.SaveAs "c:/temp/Mydoc.doc"
mydoc.Close
set mydoc = nothing


Avatar of cupper

ASKER

Richie,

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!!