[R] export graph to Word/Excel

Mark Myatt mark at myatt.demon.co.uk
Mon Apr 2 11:15:34 CEST 2001

Yu-Ling Wu <yuling5 at yahoo.com> writes:

>Thanks for your help. Now, I could write plots to 
>external files successfully.
>I am wondering if you could give me an example on
>how to write a VB program to make Word do two things:
>1. convert text into a table (dilimited by Tab)
>2. insert a object/plot
>I know some VB but I'm kind of newbie to it.

These are standard menu commands so the easiest way to get the right VB
syntax would be to record a macro of these actions (Tools -> Macro ->
Record). You can then see the code required by using Tools -> Macro ->
Edit). You can then use the VBA help system for the keywords / commands.

The above menu positions are for Word 7 (95). They may have changed in
later versions.


>--- Mark Myatt <mark at myatt.demon.co.uk> wrote:
>> Yu-Ling Wu <yuling5 at yahoo.com> writes:
>> >Hi,
>> >
>> >I have a set of script like this:
>> >
>> >----------------------
>> >summary(data)
>> >plot(time, users, type="o", xlab ="Time",
>> ylab="Number
>> >of Users")
>> >----------------------
>> >
>> >I type "rterm --slave < script.r > output.doc" and
>> the
>> >graphic doesn't
>> >actually in the output.doc file. How to make the
>> >graphic embedded in Word
>> >or Excel file?
>> I think you need to do to things:
>>         1. In R use win.metafile() or something
>> similar to store the
>>         plot in a file ... MS Office can handle a
>> variety of formats but
>>         some may need to be installed.
>>         2. Use a .VBA / .VBS script to automate Word
>> / Excel to insert
>>         an object from a file.
>> You can probable use system() to spark the .VBA
>> script from within R.

Mark Myatt

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list