Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Writing to an MS word document from VB

Posted on 2002-06-06
8
Medium Priority
?
153 Views
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>

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?

0
Comment
Question by:cupper
[X]
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
8 Comments
 

Expert Comment

by:HobbitHouse
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
0
 

Author Comment

by:cupper
ID: 7060509
Could you be more specific.
0
 

Author Comment

by:cupper
ID: 7060516
Could you be more specific.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:cupper
ID: 7060517
Could you be more specific.
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 500 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
    Selection.TypeParagraph
    .Paste
End With
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 7061826
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
 

Author Comment

by:cupper
ID: 7061999
Richie,

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

cupper
0
 
LVL 16

Expert Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

688 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