Dear all, I'm slowly making progress trying to have R talk MsWord using Rcom but I run into the following issue that I can't seem to solve:
In VBA there are situations where you can access objects using names or indexes like: ActiveDocument.Bookmarks("Compound").Select or ActiveDocument.Bookmarks(2).Name Can anyone give a clue as to how to drill down to that level because so far all my attempts fail miserably.... Thanks in advance! Rik -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Rik Schoemaker Sent: 13 December 2007 09:42 To: 'R (D)COM and RExcel server related issues' Subject: RE: [Rcom-l] Rcom and access to MsWord Dear Markus, It works; thank you very much! Kind regards, Rik -----Original Message----- From: Markus Gesmann [mailto:[EMAIL PROTECTED] Sent: 12 December 2007 17:26 To: R (D)COM and RExcel server related issues Cc: [EMAIL PROTECTED] Subject: RE: [Rcom-l] Rcom and access to MsWord Dear Rik, A similar approach for PowerPoint was discussed earlier on this list. Amending that solution for Word gives me: # create a graph and save it somewhere library(lattice) Depth <- equal.count(quakes$depth, number=8, overlap=.1) P <- xyplot(lat ~ long | Depth, data = quakes), myfile="c:\\Temp\\myPlot.wmf") win.metafile(file="c:\\Temp\\myPlot.wmf") print(P) dev.off() library(rcom) #Starts the Word application with x as handle x<-comCreateObject("Word.Application") comSetProperty(x,"Visible",TRUE) #And makes it visible comSetProperty(x,"Visible",TRUE) #Starts a new document newdoc <- comInvoke(comGetProperty(x,"Documents"),"Add") # create a new shape myShapes<-comGetProperty(newdoc,"Shapes") myPicture<-comInvoke(myShapes,"AddPicture", myfile,0,-1,80,80,400,300) Best regards, Markus -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Rik Schoemaker Sent: 12 December 2007 15:19 To: rcom-l@mailman.csd.univie.ac.at Subject: [Rcom-l] Rcom and access to MsWord Dear all, I'm playing with Rcom in an attempt to get R-generated pictures pasted into a Word document. The rcom.pdf that comes with the installation unfortunately gives me not entirely enough clues as to how to go about this. Can anyone provide me with any pointers or examples? Thanks very much in advance! Rik Schoemaker p.s. this is what is functional so far: library(rcom) #open the Microsoft Visual basic window from within Tools/Macro/Visual Basic Editor for VBA syntax #Starts the Word application with x as handle x<-comCreateObject("Word.Application") #And makes it visible comSetProperty(x,"Visible",TRUE) #Starts a new document newdoc <- comInvoke(comGetProperty(x,"Documents"),"Add") #Change directory: these both work! comInvoke(comGetProperty(x,"Application"),"ChangeFileOpenDirectory","C:\\Exp rimo\\RtoWord\\") path <- "C:\\Exprimo\\RtoWord\\test\\" comInvoke(comGetProperty(x,"Application"),"ChangeFileOpenDirectory",path) #Save file with new filename comInvoke(newdoc,"SaveAs","TEst2.doc") filename <- "NewAttempt.doc" comInvoke(newdoc,"SaveAs",filename) #these two are identical and both get the name of the new object (document) #but so far it is faily pointless! name7<-newdoc[["Name"]] nameW<-comGetProperty(newdoc,"Name") #gets the handle on the active document ActDoc<-comGetProperty(x,"ActiveDocument") #and saves it using the same name comInvoke(ActDoc,"Save") #gets a handle on the document contents CurLoc<-comGetProperty(ActDoc,"Content") #puts text at the end of the document comInvoke(CurLoc,"InsertAfter","The end.") #puts text at the beginning of the document comInvoke(CurLoc,"InsertBefore","The start.") #saves all the documents in the Word session comInvoke(comGetProperty(x,"Documents"),"Save") ---------------------------- This e-mail message has been scanned for Viruses by Norman Virus Control and it's Content by MailMarshal _______________________________________________ Rcom-l mailing list Rcom-l@mailman.csd.univie.ac.at http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l More information (including a Wiki) at http://rcom.univie.ac.at This message is intended for the personal and confidential use for the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction or as an official statement of Libero Ventures Ltd. Email transmissions cannot be guaranteed to be secure or error-free. Therefore we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. _______________________________________________ Rcom-l mailing list Rcom-l@mailman.csd.univie.ac.at http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l More information (including a Wiki) at http://rcom.univie.ac.at _______________________________________________ Rcom-l mailing list Rcom-l@mailman.csd.univie.ac.at http://mailman.csd.univie.ac.at/mailman/listinfo/rcom-l More information (including a Wiki) at http://rcom.univie.ac.at