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?

cupperAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Richie_SimonettiConnect With a Mentor IT OperationsCommented:
Try with this (besides your code):
Dim myRange As Range

Set myRange = ActiveDocument.Sections(1).Range
With myRange
    .MoveEnd Unit:=wdCharacter, count:=-1
    .Collapse Direction:=wdCollapseEnd
    Selection.TypeParagraph
    .Paste
End With
0
 
HobbitHouseCommented:
there's a "range" thing you have to set to the end of the text you just inserted, I think is your problem
0
 
cupperAuthor Commented:
Could you be more specific.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
cupperAuthor Commented:
Could you be more specific.
0
 
cupperAuthor Commented:
Could you be more specific.
0
 
iboutchkineCommented:
Dim mydoc as Word.Document

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


0
 
cupperAuthor Commented:
Richie,

Thank you much for your help!  An extra 25 points for your timely response.

cupper
0
 
Richie_SimonettiIT OperationsCommented:
You are welcome and thanks for "A" grade and extra points!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.