Moving from Microsoft Office VBA to AppleScript:
MacTech's Guide to Making the Transition
Introduction
|
Table of Contents
Page Prev and Page Next buttons at bottom of the page.
|
April, 2007
Page 103
set selectedShape to my GetSelectedShape() -- paste it in!
tell text range of text frame of selectedShape
tell its font
set {font name, font size, font color, bold} to ¬
{"Arial", 24, {255, 0, 0}, true}
end tell
end tell
end tell
In AppleScript you can set those four properties (or as many as you want) of the font all in one line as a list. Note: This only works in a tell block to the object in question, not in an of format, although you can always get a list of properties using of font.
Working with just portions of the text in a shape
Test out this macro by running it from the UI, via Tools/Macros, rather than in the VBE Editor, so you can see what's going on as it runs. Don't use text that's too long because you're going to get a new MsgBox for every character in the first part. There are four parts: the first part makes every second character blue after flashing each character in a MsgBox; the second turns each word a different shade of green after flashing each word; the third displays each complete "run" of formatted text with the Long representing its RGB value; and the fourth just displays an arbitrary portion of the text : 6 characters starting from character 3.
Sub WorkWithPartOfText()
Dim x As Long, g As Long
With ActiveWindow.Selection.ShapeRange.TextFrame.TextRange
' access one character at a time
For x = 1 To .Characters.Count
MsgBox .Characters(x)
' make every second character blue
' if x divided by 2 = x mod 2 ...
If x / 2 = x \ 2 Then
.Characters(x).Font.Color.RGB = RGB(0, 0, 255)
End If
Next
' or a word at a time:
g = 0
For x = 1 To .Words.Count
MsgBox .Words(x)
'make every word a different shade
g = g + 100
If g > 255 Then g = 0
.Words(x).Font.Color.RGB = RGB(0, g, 100)
Next
' or a "run" at a time
' every change in formatting starts a new run
' if the number of runs in a textrange is 1,
' you know that all of the text
' in the range is formatted identically.
For x = 1 To .Runs.Count
' For each run, display the text and the Long that
' represents the text's RGB color
MsgBox (.Runs(x).Text & " - " & .Runs(x).Font.Color.RGB)
Next
' or arbitrary selections of text
' 6 characters starting at position 3, for example
MsgBox .Characters(3, 6)
End With
Again, this is mostly very straightforward in AppleScript, with just one or two adaptations needed, mentioned at the end:
tell application "Microsoft PowerPoint"
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine