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.
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.


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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run code from text file in vb 1 103
Access 2013 combo box not working 3 76
Prevent user closing word document opened with VB6 6 89
Send outlook email from VBS Script 2 67
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

752 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