Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Word document to clipboard

Status
Not open for further replies.

JasonDBurke

Programmer
Jun 20, 2001
54
US
Hi I was wondering how I go about copying a Word document to the clipboard? This is the code I am trying which copies ONLY the plain text and I need it in Rich Text Format. Thanks!

---------------------------------------
Option Explicit
Dim AppWord As Word.Application
Dim copytext As Variant


Private Sub Command1_Click()
On Error Resume Next
AppWord.ActiveDocument.Close
AppWord.Quit
Set AppWord = GetObject("Word.Application")

AppWord.Visible = True
AppWord.Documents.Open ("C:\test2.doc")
AppWord.ActiveDocument.Select

copytext = AppWord.Selection '<-- only text, no format?

Clipboard.Clear
Clipboard.SetText copytext, vbCFRTF '<-- should work?

AppWord.ActiveDocument.Close
AppWord.Quit

End Sub
----------------------------------------------
 
Hi Jason,
Why do you take the detour through a String variable? That is, where the RTF info gets lost.

Try using
Selection.Copy

replace this block:
Code:
copytext = AppWord.Selection '<-- only text, no format?
  Clipboard.Clear
  Clipboard.SetText copytext, vbCFRTF  '<-- should work?

with this:
Selection.Copy

Hope this helps,
Andy

[blue]The last voice we will hear before the world explodes will be that of an expert saying:
"This is technically impossible!" - Sir Peter Ustinov[/blue]
HP:
 
Now loosing the RTF info is just what I want. I tried the DataObject.PutinClipbord (cut and paste from the help pages) and Excel just refuses on that one line. I tried exactly as help and apart from some typos in the help pages I cannot see a way round it

This is to paste unformated text in AutoCad and Excel is already open for documenting the drawing details.

Any ideas on dumping unformatted text into the clipboard?

I ended-up writing a Word Macro because it yields text at least but still formated and I cannot run from a button, only using F5 in the Visual Basic window. I deal with the formating in AutoCad manually because I don't has Lisp available - but the whole idea is to automate as much as possible to avoid finger trouble & tedium ZZZZZZZZZZzzzzzzzzzzzzzzz......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top