Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's more details on how to do this for Mac OS X:</p> <p>Get a little acquainted with the app "AppleScript Editor".</p> <p>Enter the following script into a new script window:</p> <pre><code>tell application "Microsoft Word" set d to active document get content of text object of d end tell </code></pre> <p>If you have a text document open in Word, and then you run this script, it should print the plain text of it in the Result pane below the script code.</p> <p>In the same way you can alter the text in the Word document:</p> <pre><code>tell application "Microsoft Word" set d to active document set content of text object of d to "new text" end tell </code></pre> <p>That's the basics to read and write text in Word via Applescript. Do learn how to add text to existing text or to change fonts etc, you need to read the "Dictionary" of Word, which you can open in the AppleScript Editor, see the File menu.</p> <p>For more help with AppleScript, visit <a href="http://www.macscripter.net" rel="nofollow">http://www.macscripter.net</a></p> <p>Now, to use this with REALbasic, create this script:</p> <pre><code>on run {newContent} tell application "Microsoft Word" set d to active document set content of text object of d to newContent end tell end run </code></pre> <p>Save it as a script file (file extension .scpt), e.g. as "SetContentInActiveWordDocument.scpt"</p> <p>Then drag this script file into your REALbasic project, it'll appear as an item named "SetContentInActiveWordDocument" in italics.</p> <p>You can now call this SetContentInActiveWordDocument like a function, passing a String to it.</p> <p>E.g, write:</p> <pre><code>eFile.Launch() // this should open an existing word file if it exists in "eFile" SetContentInActiveWordDocument("the new text") // replaces the text in the opened word file </code></pre> <p>To create a table in a word document, things get more complicated, though. You can pass only strings and numbers to a script from RB this way, so if you have an array of values you want to place into a table, you'll have to convert the array values into a string with unique separators, pass this string to the script, in which the string then gets split into the individual fields again.</p> <p>It also helps immensely if you purchase "Script Debugger" - that not only lets you single step through scripts but it also provides an "Explorer" that lets you see all the values of a running application, making it much easier to figure out what you want to access. I used Script Debugger to see how to get to the content just by using its Explorer. Without this, you'd have to figure it out from the Scripting Dictionary, which is usually quite difficult if you're not experienced in it.</p> <p>(later)</p> <p>I attempted to add or even just read a table with Word 2008. I can't get anything to work that references tables in the "active document", despite finding several examples on the 'net that suggest that this should work, like this:</p> <pre><code>tell application "Microsoft Word" get table 1 of active document end tell </code></pre> <p>I can't tell if this is a general problem with Word 2008 or with my particular installation. And I have no other versions to test with, sorry. This leaves you to google yourself for examples like this and see if you can make sense of it. In any case, first develop and test your code in Script Editor before trying to make it work with REALbasic.</p> <p>Also, google for "Word 2004 AppleScript Reference", which is a fairly comprehensive guide on using Word with AppleScript.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload