Writing to an MS word document from VB

Posted on 2002-06-06
Last Modified: 2010-05-02
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>


<Copy something to clipboard>


<Copy something to clipboard>


The trouble is that everytime I paste, it just replaces the previous image. I haven't used MS word in VB before.

Any suggestions?

Question by:cupper
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

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

Author Comment

ID: 7060509
Could you be more specific.

Author Comment

ID: 7060516
Could you be more specific.
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.


Author Comment

ID: 7060517
Could you be more specific.
LVL 16

Accepted Solution

Richie_Simonetti earned 125 total points
ID: 7061076
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
End With
LVL 28

Expert Comment

ID: 7061826
Dim mydoc as Word.Document

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


Author Comment

ID: 7061999

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

LVL 16

Expert Comment

ID: 7062534
You are welcome and thanks for "A" grade and extra points!!

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month7 days, 13 hours left to enroll

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question