Communicating with Word and Excel -

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dragondos
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1
Joined: Tue Jan 09, 2007 5:42 pm

Communicating with Word and Excel -

Post by dragondos » Sat Dec 06, 2008 11:17 pm

So with a respectful request can anyone guide me in the right direction with the answer to the following question:

I have created a word document and protected it so that the end user can only fill-in the details like a form and not edit the document. I would like to be able to write the code (script) which will allow my revolution programme to communicate with the word document, by opening the document and taking details either from a card or stack file and place this information directly into the appropriate position on the word document.

A similar requirement would be for communicating with an excel worksheet.

Thanks :?:

SparkOut
Posts: 2944
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Sun Dec 07, 2008 12:03 am

On Windows, this would be done by using a VBScript which Rev can "do".

Ken Ray has a feature here http://www.sonsothunder.com/devres/revo ... iac001.htm which shows a method of communicating with MS Excel.

It was written a while ago, and the method of calling the script by writing out a temporary file is not necessary since the improvement of Rev's ability to "do" a script as an alternate language if you have a recent version.

You can make a vbscript file which will open the Word or Excel object and populate it appropriately. If you put that vbscript into a field or custom property of Rev, you can then call it by something like

Code: Select all

do the cVBScript of this card as "vbscript"
depending on where you have put it. If you want, you can make the VBScript a "template" with "placeholders" like "<<fieldName>>" and if you first copy the VBScript into a variable (eg tScript) and then

Code: Select all

replace "<<fieldName>>" with field "fieldName" in tScript
before you tell Rev to

Code: Select all

do tScript as "vbscript"
then you can tailor the script to the specific requirement at runtime.

Look up "do" in the Rev dictionary. With a script called like this you will need to avoid wscript.echo and set any result to be returned to Rev by setting a variable called "result" in the vbscript. (wscript.echo can be used to return a value from a script called by the shell technique as mentioned on Ken's Sons of Thunder page).

Apart from that, you really need to be looking at vbscript tutorials and resources to learn how to interact with an MS Office App by script, such as http://www.robvanderwoude.com/vbstech_a ... _word.html or http://vbaexpress.com/kb/default.php?action=list to see what you can get them to do. (There's LOTS you can get them to do!)

You could also try writing out your information from Rev into a temporary file as the source data for a mail merge document, which you can "launch" (look up "launch" in the dictionary) and have it create a "merged" file with the data you wrote out.

Hope that helps, but it's hard to be any more specific.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun Dec 07, 2008 12:08 am

hi dragondos,

it depends a bit on your operating system and the version of word/excel you are using.
Rev can not natively access word/excel, you can get at the word document in different ways. On a Mac you can use applescript, on Windows you can use visual basic with Revolution 3.0.
Then there is a way to save the word document as rtf and you open it in Revolution and change the document and reopen it in word.
look at: http://www.runrev.com/newsletter/novemb ... etter3.php
for the rtf.
cheers
bernd

Post Reply