Word AppleScript

Similar documents
PowerPoint AppleScript

Microsoft Word - Win-Outlook.docx

OS Windows Mac OS Windows Mac OS Windows XP Mac OS X OS Windows 95 Mac OS

Microsoft Word - KUINS-Air_W10_ docx

RR-US470 (RQCA1588).indd

open / window / I / shall / the? something / want / drink / I / to the way / you / tell / the library / would / to / me

Introduction Purpose This training course demonstrates the use of the High-performance Embedded Workshop (HEW), a key tool for developing software for

syspro-0405.ppt

西川町広報誌NETWORKにしかわ2011年1月号

JavaScript の使い方

fx-9860G Manager PLUS_J

L3 Japanese (90570) 2008

はじめに

LC304_manual.ai

.NETプログラマー早期育成ドリル ~VB編 付録 文法早見表~


2 3

ProVisionaire Control V3.0セットアップガイド

2. 投稿マニュアル.xlsm

Introduction Purpose This training course describes the configuration and session features of the High-performance Embedded Workshop (HEW), a key tool

_勉強会_丸山さつき_v3

Microsoft Word - Live Meeting Help.docx

学部ゼミ新規申請方法 (Blackboard 9.1) Seminar Application Method for Undergraduate Seminar Courses ゼミ新規申請は Blackboard で受け付けます! 次セメスターにゼミ履修を希望する学生は 下記マニュアルに従ってゼミ

AN 100: ISPを使用するためのガイドライン


0.2 Button TextBox: menu tab 2

C. S2 X D. E.. (1) X S1 10 S2 X+S1 3 X+S S1S2 X+S1+S2 X S1 X+S S X+S2 X A. S1 2 a. b. c. d. e. 2

Read the following text messages. Study the names carefully. 次のメッセージを読みましょう 名前をしっかり覚えましょう Dear Jenny, Iʼm Kim Garcia. Iʼm your new classmate. These ar

New version (2.15.1) of Specview is now available Dismiss Windows Specview.bat set spv= Specview set jhome= JAVA (C:\Program Files\Java\jre<version>\

Microsoft Word - Meta70_Preferences.doc

Specview Specview Specview STSCI(Space Telescope SCience Institute) VO Specview Web page htt

Microsoft Word - KUINS-Air_W8.1_ docx

入学検定料支払方法の案内 1. 入学検定料支払い用ページにアクセス ポータルの入学検定料支払いフォームから 入学検定料支払い用 URL の ここをクリック / Click here をクリックしてください クリックを行うと 入学検定料支払い用のページが新たに開かれます ( 検定料支払い用ページは ポ

Actual ESS Adapterの使用について

25 II :30 16:00 (1),. Do not open this problem booklet until the start of the examination is announced. (2) 3.. Answer the following 3 proble

VE-GP32DL_DW_ZA

平成29年度英語力調査結果(中学3年生)の概要

SpecimenOTKozGo indd

VE-GD21DL_DW_ZB

D0050.PDF

ron.dvi

ストラドプロシージャの呼び出し方

1 # include < stdio.h> 2 # include < string.h> 3 4 int main (){ 5 char str [222]; 6 scanf ("%s", str ); 7 int n= strlen ( str ); 8 for ( int i=n -2; i

高等学校 英語科

13 Student Software TI-Nspire CX CAS TI Web TI-Nspire CX CAS Student Software ( ) 1 Student Software 37 Student Software Nspire Nspire Nspir

橡実践Oracle Objects for OLE

74 No ACCESS

RX600 & RX200シリーズ アプリケーションノート RX用仮想EEPROM

Page 1 of 6 B (The World of Mathematics) November 20, 2006 Final Exam 2006 Division: ID#: Name: 1. p, q, r (Let p, q, r are propositions. ) (10pts) (a

コンピュータ概論

A B C B C ICT ICT ITC ICT

,,,,., C Java,,.,,.,., ,,.,, i

L1 What Can You Blood Type Tell Us? Part 1 Can you guess/ my blood type? Well,/ you re very serious person/ so/ I think/ your blood type is A. Wow!/ G


C H H H C H H H C C CUTION:These telephones are for use in Japan only. They cannot be used in other countries because of differences in voltages, tele


取説_VE-PV11L(応用編)

評論・社会科学 84号(よこ)(P)/3.金子

情報資源組織演習B:


1 I EViews View Proc Freeze

PowerPoint プレゼンテーション

NO

45 VBA Fortran, Pascal, C Windows OS Excel VBA Visual Basic Excel VBA VBA Visual Basic For Application Microsoft Office Office Excel VBA VBA Excel Acc


GP05取説.indb

きずなプロジェクト-表紙.indd

C FGIH C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C


h23w1.dvi


LiveCode初心者開発入門サンプル

VB参考資料 Wordに依る利用

PowerPoint プレゼンテーション

Ver.1 1/17/2003 2

PFQX2227_ZA

D0120.PDF

2

AuthorManual_JSTP.ppt

Web of Scienceの使い方. 2004年12月版

C-720 Ultra Zoom 取扱説明書

2

2

24 Depth scaling of binocular stereopsis by observer s own movements

名称未設定

Answers Practice 08 JFD1

1 ( 8:12) Eccles. 1:8 2 2


一 先 行 研 究 と 問 題 の 所 在 19

*Ł\”ƒ‚ä(CV03)

\615L\625\761\621\745\615\750\617\743\623\6075\614\616\615\606.PS

MOTIF XF 取扱説明書

Microsoft Word - PrivateAccess_UM.docx

elemmay09.pub


WordPress Web


help gem gem gem my help


I N S T R U M E N T A T I O N & E L E C T R I C A L E Q U I P M E N T Pressure-resistant gasket type retreat method effective bulk compressibility Fro

Transcription:

(URL Web ) Microsoft Excel Entourage PowerPoint Microsoft Corporation Apple Apple Mac Mac OS Apple Inc. 2008 Microsoft Corporation. All rights reserved.

Word AppleScript...4...5...11...16...20...34 3

Word AppleScript の基本 Microsoft Word AppleScript Visual Basic for Applications (VBA) ( ) AppleScript スクリプトをテストする際に activate コマンドを使用する Macintosh activate Word activate Word [ ] activate Word 参考資料 Word Word 2004 AppleScript (http://download.microsoft.com/download/a/0/7/a07d8bde-8903-4a78-bd84- E2CF6A9DCF33/Word2004AppleScriptRef_J.pdf) Word Dictionary ( text range ) AppleScript Word 同じ名前のクラスとプロパティ VBA Range AppleScript text range Text Suite VBA Range AppleScript text object text range AppleScript font font object " " テキスト範囲の変更 VBA AppleScript 4

文書を開く ドキュメントを作成する AppleScript Visual Basic for Applications (VBA) VBA Application.Documents.Add AppleScript make new document AppleScript with properties Word で新しい文書を作成する Microsoft Word AppleScript VBA Add VBA VBA Documents.Add Template NewTemplate DocumentType Visible Document 50 AppleScript VBA Set NewDoc = Documents.Add With NewDoc.Content.Font.Name = "Arial".Text = "Here is some Text." End With 5

AppleScript set newdoc to make new document with properties {text object: {font object:{name:"arial"}, content: "Here is some text."}} text object Dictionary VBA document text object set newdoc to make new document tell newdoc's text object set name of font object to "Arial" set content to "Here is some text." VBA Documents.Add 4 AppleScript.Visible = False AppleScript window 1 collapsed true VBA NewTemplate True AppleScript AppleScript save as file format template NewTemplate:=True VBA AppleScript save as file format format template Macintosh DocumentType wdnewblankdocument wdnewwebpage DocumentType:= wdnewwebpage VBA AppleScript file format format HTML view online view set view type of view of window 1 of newdoc to online view 6

テンプレートから文書を作成する attached template プロパティを使用する AppleScript Visual Basic for Applications (VBA) Add Template make new document with properties attached template set newdoc to make new document set attached template of newdoc to "Mac HD:Applications:" & "Microsoft Office 2004:My Templates:Test Template.dot" get name of attached template of newdoc Dictionary " " Macintosh POSIX file "" as alias as Unicode text Test Template.doc attached template プロパティの問題を回避する attached template insert file ( ) document set templatepath to "Mac HD:Applications:" & "Microsoft Office 2004:My Templates:Test Template.dot" set newdoc to make new document set attached template of newdoc to templatepath insert file at text object of newdoc file name templatepath attached template application automation security 2 templatepath 7

特別なページ設定を取得する page setup ( ) set templatepath to "Mac HD:Applications:" & "Microsoft Office 2004:My Templates:Test Template.dot" " activate set newdoc to make new document set attached template of newdoc to templatepath set thetemplate to attached template of newdoc -- a template object now set editabletemplate to open as document thetemplate -- a document set pagesetupprops to properties of (get page setup of editabletemplate) set linenumberprops to properties of (get line numbering of pagesetupprops) close editabletemplate saving no tell page setup of newdoc set its properties to pagesetupprops tell its line numbering set its properties to linenumberprops insert file at text object of newdoc file name templatepath open as document document page setup document page setup properties AppleEvent 30 1 1 properties Microsoft Office page setup line numbering line numbering page setup properties 8

newdoc page setup line numbering 30 30 30 class 1 line numbering マクロのセキュリティ警告を表示しない make new document with properties do Visual Basic "Documents.Add Template:=\"Mac HD:" & "Applications:Microsoft Office 2004:My Templates:Test Template.dot\"" Documents.Add Template Microsoft Word 2004 for Mac 既存の文書を開く AppleScript Visual Basic for Applications (VBA) VBA Documents.Open FileName:="Mac HD:Folder:Filename.doc" AppleScript open alias "Mac HD:Folder:Filename.doc" VBA Open AppleScript (Standard Suite ) open AppleScript Microsoft Word VBA AppleScript 9

文書を開いて変更する VBA Dim odoc As Document Set odoc = Documents.Open FileName:="Mac HD:Folder:Filename" With odoc.hyphenationzone = InchesToPoints(0.25).HyphenateCaps = False.AutoHyphenation = True End With VBA ( ) Document Open Document AppleScript Standard Suite open open コマンドに関する問題を回避する Standard Suite Apple Standard Suite Word 10 VBA Open open open open " Mac HD:Folder:Filename.doc" set thedoc to active document tell thedoc set hyphenation zone to (inches to points inches 0.25) set hyphenate caps to true set auto hyphenation to true document active document ( ) 開いている文書で open コマンドを使用する open 10

open try set thedoc to document "Filename.doc" on error open "Mac HD:Folder:Filename.doc" set thedoc to active document end try tell thedoc set hyphenation zone to (inches to points inches 0.25) set hyphenate caps to true set auto hyphenation to true コレクションとクラスのリスト AppleScript ( ) Dictionary application selection 1 (Dictionary contained by ) every [ クラス名 ] 構文 every [ ] Visual Basic for Applications (VBA) For Each AppleScript repeat repeat with someobject in (every element) repeat with i from 1 to (count every element) VBA For Each ofield In ActiveDocument.Fields ofield.unlink Next ofield 11

AppleScript set allfields to (every field of active document) repeat with ofield in allfields unlink ofield end repeat VBA Fields AppleScript every field リストで使用できないことが多いコマンド AppleScript repeat unlink (every field of active document) get {field 1 of active document, field 2 of active document,...} unlink Microsoft Word Excel PowerPoint Entourage VBA repeat repeat ループを使用するときに変数に複数形を割り当てる AppleScript repeat allfields get repeat with ofield in (get every field of active document) unlink ofield end repeat field 1 12

repeat with i from (count (get every field of active document)) to 1 by -1 set ofield to item i of (get every field of active document) unlink ofield end repeat get repeat with i from -1 count get every field of active document 2 AppleEvent AppleEvent allfields repeat with i set allfields to (every field of active document) repeat with i from 1 to (count allfields) set ofield to item i of allfields unlink ofield end repeat 他のクラスの要素であるクラスを使用する VBA VBA AppleScript Dim ofield As Field Dim osection As Section Dim oheader As HeaderFooter Dim ofooter As HeaderFooter For Each osection In ActiveDocument.Sections For Each oheader In osection.headers If oheader.exists Then For Each ofield In oheader.range.fields ofield.unlink Next ofield End If Next oheader 13

For Each ofooter In osection.footers If ofooter.exists Then For Each ofield In ofooter.range.fields ofield.unlink Next ofield End If Next ofooter Next osection Ranges AppleScript header footer section AppleScript header footer AppleScript ( ) 0 make new element at someobject Word Excel PowerPoint Add Section HeaderFooters 3 (primary first page even pages) AppleScript header footer section Dictionary base object これらのクラスに対して専用のコマンドを使用する header footers of section 1 of active document get header get footer index VBA Section Headers Footers ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary) 14

AppleScript get header (section 1 of active document) index header footer primary VBA ActiveDocument.Sections(1).Headers AppleScript 2 (range) 1 repeat 2 set thesections to every section of active document repeat with thesection in thesections set theheaderfooters to {get header thesection index header footer primary} & {get header thesection index header footer first page} & {get header thesection index header footer even pages} & {get footer thesection index header footer primary} & {get footer thesection index header footer first page} & {get footer thesection index header footer even pages} repeat with theheaderfooter in theheaderfooters set thefields to every field of text object of theheaderfooter repeat with thefield in thefields unlink thefield end repeat end repeat end repeat 15

これらのクラスに対して存在 (exists) テストを行わない AppleScript VBA header footers exists VBA ( ) first page even pages ( wdheaderfooterfirstpage wdheaderfooterevenpages) AppleScript get header get footer header footer first page even pages text object of theheaderfooter thefields 検索と置換 Microsoft Word Visual Basic for Applications (VBA) AppleScript グローバルな検索と置換 Word VBA ( ) AppleScript VBA Sub ReplaceEverywhere(FindText As String, ReplaceText as String) Dim osection As Section Dim oshape As Shape Dim ohf As HeaderFooter ReplaceInRange FindText, ReplaceText, ActiveDocument.Content For Each oshape In ActiveDocument.Shapes If oshape.textframe.hastext Then ReplaceInRange FindText, ReplaceText, oshape.textframe.textrange End If Next oshape For Each osection In ActiveDocument.Sections For Each ohf In osection.headers ReplaceInRange FindText, ReplaceText, ohf.range For Each oshape In ohf.shapes If oshape.textframe.hastext Then ReplaceInRange FindText, ReplaceText, _ oshape.textframe.textrange End If Next oshape 16

End Sub Next ohf For Each ohf In osection.footers ReplaceInRange FindText, ReplaceText, ohf.range For Each oshape In ohf.shapes If oshape.textframe.hastext Then ReplaceInRange FindText, ReplaceText, oshape.textframe.textrange End If Next oshape Next ohf Next osection Sub ReplaceInRange(FindText As String, ReplaceText as String, _ orange as Range) With orange.find.format = False.Text = FindText.Replacement.Text = ReplaceText.Wrap = wdfindstop.execute Replace:=wdReplaceAll End With End Sub AppleScript on ReplaceEverywhere(findText, replacetext) local theshape, therange, theheaderfooters, theheaderfooter --first find and replace in the body (main story) of document set therange to text object of active document my ReplaceInRange(findText, replacetext, therange) --nowin all shapes set allshapes to (every shape of active document) repeat with theshape in allshapes set thetextframe to (text frame of theshape) if has text of (text frame of theshape) then --note:'text range', not 'text object' of text frame set therange to text range of text frame of theshape my ReplaceInRange(findText, replacetext, therange) end if end repeat -- now in the headers and footers of each section 17

set allsections to every section of active document repeat with thesection in allsections set theheaderfooters to {get header thesection index header footer primary} & {get header thesection index header footer first page} & {get header thesection index header footer even pages} & {get footer thesection index header footer primary} & {get footer thesection index header footer first page} & {get footer thesection index header footer even pages} repeat with theheaderfooter in theheaderfooters set therange to text object of theheaderfooter my ReplaceInRange(findText, replacetext, therange) --now in their shapes set allshapes to (every shape of theheaderfooter) repeat with theshape in allshapes if has text of (text frame of theshape) then --note:'text range', not 'text object' of text frame set therange to text range of text frame of theshape my ReplaceInRange(findText, replacetext, therange) end if end repeat end repeat end repeat end ReplaceEverywhere on ReplaceInRange(findText, replacetext, therange) set findobject to find object of therange tell findobject set format to false set content to findtext set content of its replacement to replacetext set wrap to find stop 18

end ReplaceInRange execute find findobject replace replace all tell ブロックでコマンドとパラメータを配置する range ReplaceInRange findobject (text range findobject ) tell VBA Execute With AppleScript execute find (findobject) tell findobject tell AppleScript it execute find tell tell findobject set format to false set content to findtext set content of its replacement to replacetext set wrap to find stop execute find it replace replace all 同じ名前のクラスとプロパティ Drawing Suite text frame (text object ) text range range find findobject font font object text range text object text frame text range whose text frame tell its 1 findobject tell ReplaceInRange its replacement replacement its findobject replacement replacement ( ) 19

頻繁に使用するハンドラをコピーしてペーストする " " ( ) 2 ReplaceEverywhere "hot" "cold" my ReplaceEverywhere("hot", "cold") " " AppleScript " " ハンドラ呼び出しで my を使用する ReplaceEverywhere("hot", "cold") tell my Word tell my " " ReplaceEverywhere my 削除する インデックスを使用してオブジェクトを参照する AppleScript 逆方向に移動するループを使用して項目を削除する "by -1" repeat VBA Sub DeleteRows() Dim TargetText As String Dim orow As Row If Selection.Information(wdWithInTable) = False Then Exit Sub 20

TargetText = InputBox$("Enter target text:", "Delete Rows") For Each orow In Selection.Tables(1).Rows If orow.cells(1).range.text = TargetText & vbcr & Chr(7) Then orow.delete Next orow End Sub AppleScript set cellendchar to ASCII character 7 if (get selection information selection information type (with in table)) = "false" then return display dialog "Delete rows with this text in cell 1:" default answer "Enter target text" with icon 1 set targettext to text returned of result set therows to every row of table 1 of selection repeat with i from (count therows) to 1 by -1 set therow to item i of therows if content of text object of cell 1 of therow = (targettext & return & cellendchar) then delete therow end if end repeat 特定の文字を呼び出すコマンドを使用しない AppleScript ASCII character 7 Visual Basic for Applications (VBA) Chr(7) Microsoft Word VBA vbcr Chr(13) AppleScript return ASCII character 13 ASCII character Standard Additions Dictionary Dictionary Macintosh 1. [Word] [ ] 2. [Word ] [ ] [ ] 3. [ ] [ ] [ ] 21

repeat 1 AppleScript return space tab ASCII character (13 31 9) Word 2004 Word tell tab tab tab stop tab AppleScript return return (targettext & return & cellendchar) 繰り返しループでの項目の削除方法 AppleScript repeat VBA For Each AppleScript repeat with therow in the Rows repeat with therow in (every row of table 1 of selection) repeat with i from 1 to (count therows) delete (count therows) to 1 by -1 1 [a, b, c] 3 item 1 (a) item 2 item 3 (c) item 1 item 2 (b) [b, c] Item 1 2 with in table (with in ) true false true false 範囲を使用する AppleScript 変更を加えた範囲をキャプチャして新しい変数に割り当てる Text Range 22

Visual Basic for Applications (VBA) Dim AmountMoved As Long Dim myrange As Range 'start with first paragraph and extend range down to second Set myrange = ActiveDocument.Paragraphs(1).Range AmountMoved = myrange.moveend(unit:=wdparagraph, Count:=1) 'loop until there are no more paragraphs to check Do While AmountMoved > 0 'if two paragraphs are identical, delete second one 'and add the one after that to myrange so it can be checked If myrange.paragraphs(1).range.text = _ myrange.paragraphs(2).range.text Then myrange.paragraphs(2).range.delete AmountMoved = myrange.moveend(unit:=wdparagraph, Count:=1) Else 'if two paragraphs aren't identical, add the one 'after that to my range, so it can be checked, and 'drop the first one, since it is no longer of 'interest. AmountMoved = myrange.moveend(unit:=wdparagraph, Count:=1) myrange.movestart unit:=wdparagraph, Count:=1 End If Loop AppleScript --start with first paragraph and extend range down to second set myrange to text object of paragraph 1 of active document set rangeend to end of content of myrange --in AppleScript a new range is made and returned, cannot alter --ranges in place, so redefine myrange to the new range set myrange to (move end of range myrange by a paragraph item count 1) set newrangeend to end of content of myrange set amountmoved to newrangeend - rangeend 23

set rangeend to newrangeend --loop until there are no more paragraphs to check repeat while amountmoved > 0 --if two paragraphs are identical, delete second one --and add the one after that to myrange so it --can be checked if content of text object of paragraph 1 of myrange = content of text object of paragraph 2 of myrange then delete text object of paragraph 2 of myrange set myrange to text object of paragraph 1 of myrange set rangeend to end of content of myrange set myrange to (move end of range myrange by a paragraph item count 1 set newrangeend to end of content of myrange set amountmoved to newrangeend - rangeend set rangeend to newrangeend end repeat else end if --if two paragraphs aren't identical, add --the one after that to my range, so it can --be checked, and drop the first one, since --it is no longer of interest. set myrange to (move end of range myrange by a paragraph item count 1 try set newrangeend to end of content of myrange set amountmoved to newrangeend - rangeend set rangeend to newrangeend set myrange to (move start of range myrange by a paragraph item count 1 on error -- errors because can't get --newrangeend when move end of range --is missing value at end of document set amountmoved to 0 end try 2 AppleScript myrange 24

AppleScript set range (VBA ) set range (myrange ) VBA set range コマンドを使用する 3 myrange Set myrange = ActiveDocument.Paragraphs(1).Range myrange.setrange Start:=myRange.Start, _ End:=ActiveDocument.Paragraphs(3).Range.End VBA 3 myrange SetRange myrange AppleScript myrange text object of paragraph 1 ( 1 ) set range Microsoft Word (move end of range ) myrange range set par1range to text object of paragraph 1 of active document set myrange to create range active document start (start of content of par1range) end (end of content of par1range) set myrange to set range myrange start (start of content of myrange) end (end of content of (get text object of paragraph 3 of active document)) content of myrange myrange par1range set range paragraph 3 set range myrange myrange VBA myrange 25

移動文字数を取得する set range set par1range to text object of paragraph 1 of active document set par3range to text object of paragraph 3 of active document set myrange to create range active document start (start of content of par1range) end (end of content of par3range) content of myrange move end of range move start of range VBA MoveEnd MoveStart VBA end of content (amountmoved) set rangeend to newrangeend rangeend newrangeend VBA Set myrange = ActiveDocument.Paragraphs(1).Range AmountMoved = myrange.moveend(unit:=wdparagraph, Count:=1) myrange range MoveEnd myrange MoveEnd AppleScript text object move end of range myrange move end of range set myrange to text object of paragraph 1 of active document set myrange to (move end of range myrange by a paragraph item count 1) 26

rangeend VBA AppleScript エラーをトラップしてスクリプトを終了する 1 VBA MoveEnd 0 AppleScript move end of range missing value null get end of content try/on error amountmoved 0 VBA AppleScript repeat/while move end move start delete get end of content amountmoved while repeat このタスクの最適なコード例 AppleScript --start with first paragraph and extend range down to second set myrange to text object of paragraph 1 of active document set myrange to (move end of range myrange by a paragraph item count 1) --loop until there are no more paragraphs to check repeat --if two paragraphs are identical, delete second one --and add the one after that to myrange so it can be checked if content of text object of paragraph 1 of myrange = content of text object of paragraph 2 of myrange then delete text object of paragraph 2 of myrange set myrange to text object of paragraph 1 of myrange set myrange to (move end of range myrange by a paragraph item count 1) else --if two paragraphs aren't identical, add the one --after that to my range, so it can be checked, --and drop the first one, since it is no longer --of interest. set myrange to (move end of range myrange by a paragraph item count 1) 27

end repeat end if try set myrange to (move start of range myrange by a paragraph item count 1) on error -- last paragraph --(missing value, so can't move start) exit repeat -- finish end try 逆方向に反復処理を行って行を削除する AppleScript VBA Public Sub DeleteEmptyRows() Dim otable As Table, orow As Range, ocell As Cell, Counter As Long, _ NumRows As Long, TextInRow As Boolean ' Specify which table you want to work on. Set otable = Selection.Tables(1) ' Set a range variable to the first row's range Set orow = otable.rows(1).range NumRows = otable.rows.count Application.ScreenUpdating = False For Counter = 1 To NumRows StatusBar = "Row " & Counter TextInRow = False For Each ocell In orow.rows(1).cells If Len(oCell.Range.Text) > 2 Then 'end of cell marker is actually 2 characters TextInRow = True Exit For End If Next ocell If TextInRow Then Set orow = orow.next(wdrow) Else orow.rows(1).delete End If Next Counter 28

Application.ScreenUpdating = True End Sub AppleScript activate --Specify which table you want to work on set thetable to table 1 of selection -- or table 1 of active document set numrows to number of rows of thetable -- faster than counting rows set screen updating to false --iterate backwards because deleting! repeat with i from numrows to 1 by -1 set rowtext to text object of row i of thetable set status bar to "Row " & i set textinrow to false --you NEED the explicit gets if not setting variables! repeat with thecell in (get every cell of rowtext) if (count of (get content of text object of thecell)) > 2 then -- end of cell marker is 2 characters, -- count faster than length set textinrow to true exit repeat -- no need to check other cells end if end repeat if not textinrow then delete row 1 of rowtext end if end repeat set screen updating to true AppleScript repeat AppleScript Visual Basic for Applications (VBA).Next(wdRow) 29

repeat ループはリスト内のインデックス順のオブジェクトにアクセスする repeat set allrows to every row of thetable {row 1 of table 1, row 2 of table 1, row 3 of table 1,...} item i set allrows to every row of thetable repeat with i from 1 to (countallrows) set therow to item i of allrows リストのインデックスはリスト内のオブジェクトを削除すると変化する row i of thetable row i of the table row i Microsoft Entourage ID " " " " " " ID allmessages {message id 12345, message id 12346, message id 12347, message id 12348} 2 allmessages item 3 id 12348 id 12347 Microsoft Word Finder AppleScript インデックスの代わりに一意の ID を使用する active document Word Word thedoc 1. thedoc active document 2. window 1 Dock (collapse) 3. thedoc 30

active document ID name 2 set thename to name of active document set thedoc to document thename thedoc " " Dock active window thedoc 行削除時のエラーを防ぐために逆方向に反復処理する allrows {row 1 of table 1, row 2 of table 1,...} every row Dictionary table row " " " " name repeat with i from numrows to 1 by -1 i VBA AppleScript Set orow = otable.rows(1).range AppleScript repeat set rowtext to text object of row 1 of thetable textinrow true i true screen updating status bar AppleScript VBA 1 31

検索と置換を使用する repeat -1 repeat Microsoft Word 2004 for Mac Windows Microsoft Word Windows Word [ ] " " ^p 2 {2,} Windows Word [ ] ^p ^13 "^13{2,}" [ ] Word 2004 UI Visual Basic for Applications (VBA) AppleScript ^13 ^13{2,} UI find UI Macintosh ^13 ^p 2 ^p^p Replace All VBA AppleScript VBA 'Note that using Find and Replace is dramatically faster 'than cycling through the Paragraphs collection 'Replace: ^13{2,} with ^p, which replaces all occurrences 'of two or more consecutive paragraph marks with one paragraph mark With ActiveDocument.Range.Find.Text = "^13{2,}".Replacement.Text = "^p".forward = True.Wrap = wdfindcontinue.format = False.MatchCase = False.MatchWholeWord = False.MatchAllWordForms = False.MatchSoundsLike = False 32

End With.MatchWildcards = True.Execute Replace:=wdReplaceAll 'However, you can't use Find & Replace to delete the first or last 'paragraph in the document, if they are empty. To delete them: Dim MyRange As Range Set MyRange = ActiveDocument.Paragraphs(1).Range If MyRange.Text = vbcr Then MyRange.Delete Set MyRange = ActiveDocument.Paragraphs.Last.Range If MyRange.Text = vbcr Then MyRange.Delete AppleScript -- replace ^p^p with ^p to replace all occurrences of two -- consecutive paragraph marks with one paragraph mark -- repeat until done repeat set textobject to (text object of active document) -- redo each time if (content of textobject) does not contain (return & return) then exit repeat -- done end if set findobject to (find object of textobject) -- we need a separate executefind on it, -- so best set a variable to it so we just get -- it once tell findobject set {content, content of its replacement, forward, wrap, format, match case, match whole word, match all word forms, match sounds like, match wildcards} to {"^p^p", "^p", true, find continue, false, false, false, false, false, false} execute find findobject replace replace all -- Find/Replace cannot delete first or last -- paragraph if empty, so: set myrange to text object of paragraph 1 of active document if content of myrange = return then delete myrange 33

try end try end repeat set myrange to text object of paragraph -1 of active document if content of myrange = return then delete myrange ^p ^13 Word repeat repeat repeat while (get text object of active document does not contain return & return) repeat textobject exit repeat 2 repeat try/end try myrange ( ) try/error text object of active document set textobject to (text object of selection) -- redo each time ブックマーク ブックマークを使用する Microsoft Word 2004 2008 1. [Word] [ ] [ ] 2. [ ] [ ] Visual Basic for Applications (VBA) AppleScript 2 ( ) 34

VBA ActiveDocument.Bookmarks("myBookmark").Range.Text= "Inserted Text" AppleScript set content of text object of bookmark "mybookmark" of active document to "Inserted Text" ( ) VBA Dim bmrange As Range Set bmrange = ActiveDocument.Bookmarks("myBookmark").Range bmrange.text = "Inserted Text" ActiveDocument.Bookmarks.Add _ Name:="myBookmark", _ Range:=bmRange AppleScript set bmrange to text object of bookmark "mybookmark" of active document set content of bmrange to "Inserted Text" make new bookmark at active document with properties {name:"mybookmark", text object:bmrange} 動的な範囲はブックマークのスクリプトに影響する AppleScript AppleScript text range bmrange 2 1. tell 1 bmrange properties of bmrange 2 2. 2 35

2 1. tell bmrange "Inserted Text" properties of bmrange 3 2. 3 content bmrange text object ブックマークの場所を特定して独自のブックマークを作成する 1. bmrange start of content start of bookmark 2. bmrange (count) 3. start of content end of content end of bookmark start of content start of content 0 1 end of content 1 start of bookmark end of bookmark 2 text object set bmrange to text object of bookmark "mybookmark" of active document set bmstart to bmrange's start of content set content of bmrange to "Inserted Text" set bmend to bmstart + (count "Inserted Text") make new bookmark at active document with properties {name:"mybookmark", start of bookmark:bmstart, end of bookmark:bmend} AppleScript VBA VBA AppleScript 36