Help with converting short Microsoft Word maco to Applescript

I am switching from PC to Mac and used macros in MS Word. I am not a programer and have been trying to convert 3 macros to Applescript. I just can’t get it. Can someone help me convert the following to 3 Applescripts for Mac Word 08?
Here are the macros:

’ Macro1

Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.LanguageID = wdEnglishUS
Application.CheckLanguage = True
With Selection.Font
.Name = “Lucida Sans Unicode”
.Size = 12
. .Color = wdColorBlue
. End With
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=2
End Sub

’ Macro2

Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.LanguageID = wdItalian
Application.CheckLanguage = True
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=1

End Sub

’ Macro3

With Selection.Font
.Name = “Lucida Sans Unicode”
.Size = 12
.StrikeThrough = True
.Color = wdColorPink
End With
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=" "
With Selection.Font
.Name = “Lucida Sans Unicode”
.Size = 12
.StrikeThrough = False
.Color = wdColorBlue
.End With
End Sub

Hi,

in the last few months there were a few requests to convert VBA to AS.
Many members of this forum have excellent AppleScript skills but almost nobody knows VBA.

The more detailed you can describe the function of the macros
the more answers you could get :wink:

Excellent advice. Describe in some detail what you want to do, or precisely what your scripts are supposed to do.

Thanks Adam and StefanK
Below is a description of each of the three needed scripts.
Thanks
Mark

Script 1
While in MS Word
With the curser at the beginning of a blank line.
Select the line
Set the language for the line to English
Change the font color to blue
Move curser down 2 lines to the beginning of the new line.

(I am starting with several lines of Italian. I am inserting a blank line between each and then using the script to make all the new blank lines ready to be English and the color blue to contrast it from the Italian)
Note: If you have not used the “set Language” command before it is a little hard to find in Mac Word O8. I had to go into “Customize Toolbars and Menus…” select the “Commands” Tab, Select “Tools” under “Categories”, under Commands drag “Set Language” to the toolbar. Now with whatever you have highlighted in your document you can select “Language” on the Toolbar and select the language you want for the highlighted text. Spelling and grammar are checked using the correct dictionaries.

Script 2
While in MS Word
With a word or group of words highlighted
Make selected text strikethrough and pink
Enter a space and change the color to blue
(ready for the next entry)

Script 3
While in MS Word
Select the line the curser is on and set the language to Italian

Hi,

try this for the first macro


tell application "Microsoft Word"
	set theLine to (get selection information selection information type first character line number) as integer
	set myRange to my setRange(theLine)
	
	set language ID of myRange to english us
	tell font object of myRange to set color index to blue
	
	set myRange to my setRange(theLine + 2)
	collapse range myRange direction collapse start
end tell

on setRange(lineNumber)
	tell application "Microsoft Word"
		return (create range active document start (start of content of ¬
			text object of paragraph lineNumber of active document) end (end of content ¬
			of text object of paragraph lineNumber of active document))
	end tell
end setRange

Thanks Stefan
I will check it out this evening after work.
Mark

Hi Stefan
I have tried to understand your script. I’m sorry I’m lost. What is (get selection information selection information type first character line number). How would someone know to use this text?
It is quite difficult for me to troubleshoot the script because I don’t what I am looking for. Is there a way to step though scripts comand by comand?

Here is what I am seeing:
I place the curser on the first blank line after the Italian line (the first line of the document) and run the script. The curser disappears. I can get it to appear again if I click the top banner of the Word window. The curser appears two lines below the first blank line. On inspection, I see that the first blank line is now English and blue. With the curser at this new location I run the macro again, assuming it will make the new line English and blue and then move down two more lines. What appears to be happing is the curser disappears again. After clicking top banner of the Word window I find the curser at the beginning of the first line of the document. The second blank line is unchanged, and is still Italian and black.

Another piece of info is that after the script has run it adds text to the info field with the “Result” highlighted. The text says:

text range id «data iWrg0000000000000000» of document “Silvia script test.docx” of application “Microsoft Word”

“Silvia script test.docx” is the name of the file I was using to test in.
Suggestions?
Thanks
Mark

It determines the line containing the cursor.
I tested the script with Word 2004, maybe there are changes in 2008

Microsoft has published an AppleScript Reference for Word 2004
and there is an online vba-to-applescript-transition-guide

Hi Stefan
Thanks for the references, the very gracious attempt and the information.
I must say I am still clueless regarding these three scripts. I doubt I will have much need for writing scripts after these three. It appears leaning Applescript at least for me is going to take much more time than I have to spend on the project especially with the 3 script goal. Is there someone out there who would be willing to write the scripts for me. I’m not sure how to accomplish payment, but I would be very willing to pay for the 3 functioning scripts.
Thanks
Mark

Hi Jacques
At first glance they look like they are working. Thank you very much! I do have a question though. When I get home this eveing I will do a little more testing and post my question. Again thanks
Mark

Hi Jacques
When I run the first and second scripts I get a message like the following in the lower window of the script editor, when the “Result” tab is highlighted":
text range id «data iWrg2602000026020000» of document “Silvia script test.docx” of application “Microsoft Word”
“Silvia script test.docx” is the name of the file I was using to test with.
The number after iWrg changes each time I run the script.
Does this mean there is a problem?
There is no message with the third script.
The scripts seem to work.
Thanks
Mark

As “Result” implies, the content of the window is the result of the last executed line, that’s all :slight_smile:

Thanks Stefan for the info.:slight_smile:
Jacques, just to let you know, I worked wth the scripts last night and they work perfectly.
Thank you very much
:smiley:
Mark