Applescript: Tuning comment' content in MS Word

Hello,


I am trying to add comments into MS Word document with Applescript.


I can inser tcomment itself with deriverd from this forum sentence:


makenewWord commentatselectionwith properties {comment text:"review this"}


Then I need to change color of text in this comment. The obvious way is to get reference to this freshly created comment, extract

get comment text property as text object and set up font properties to that object.


But I cannot figure how to get reference to this comment. I tried:


set anchor to makenewWord commentatselectionwith properties {comment text:"review this"}


and anchor is set to:

Word comment 1 of text range id «data iWrg1E0300001E030000» of document "Документ2"


but i got:


get properties of anchor


--> missing value


Then I tried:


set curText to get properties of selection


but it returns no mention of the Word Comment element :-(



get properties of selection


--> {class:selection object, content:"T", formatted text:formatted text of selection, selection start:807, selection end:807, font object:font object of selection, selection type:selection ip, story type:main text story, style:Word style "Обычный" of selection, footnote options:footnote options of selection, endnote options:endnote options of selection, show Word comments by:"All Reviewers", border options:border options of selection, shading:shading of selection, paragraph format:paragraph format of selection, page setup:page setup of selection, show hidden bookmarks:false, story length:888, language ID:russian, language ID east asian:russian, supplemental language ID:russian, column options:missing value, row options:missing value, header footer object:missing value, is end of row mark:false, bookmark id:0, previous bookmark id:0, find object:findid «data iWio68E00A7C» of selection, text object:text object of selection, selection flags:selection active and replace, active:true, start is active:false, IP at end of line:false, extend mode:false, column select mode:false, orientation:text orientation horizontal, document:document of selection, no proofing:false, fit text width:0.0, range footnote options:range footnote options of selection, range endnote options:range endnote options of selection}


At the same time:



get every Word comment of document "Документ2"


--> {Word comment 1 of document "Документ2"}



My question is - how to get reference to the Word Comment object created in my Applescript? I cannot use list with all comments (last fragment) because I don't know where exctly my last command is in this list. I cannot distinguish it by texts, because several comments can contain the same "words" but should be of different colors.


Regards,

Vladimir

iMac, Mac OS X (10.7.2), WorkHorse

Posted on Jan 14, 2013 7:35 AM

Reply
1 reply

Jan 15, 2013 2:10 AM in response to vodolazkiy

Sometimes we need just to make break and look for an alternative solution 😉


Below is solution, which is working. I understand, that this not a straightforward solution, but... it works.


tell application "Microsoft Word"


-- Initially we set up sensless text to

set tempString to "QWQWWQQ"

-- create new comment with predefined comment text

makenewWord commentatselectionwith properties {comment text:tempString}

-- get list of all comments in current (active) document

set curComment to Word comments of active document

-- search for document, we entered last

repeat with oComment in curComment

set insertedText to comment text of oComment

if (content of insertedText is equal to tempString) then

-- set color for comment

set fontColor to ({31270, 38327, 65535} as RGB color)

set textik to text object of insertedText

set myFont to font object of insertedText

-- replace comment's color with custom color

set color of myFont to fontColor

-- replace "search key" for the actual comment

set content of insertedText to "Insert comment text here!!!"

exit repeat

end if

end repeat

end tell

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript: Tuning comment' content in MS Word

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.