Bonjour,

Je vous soumet un petit code.
Juste le copier dans un Editeur et le lancer
Il faut penser à ouvrir word avec un doc vierge avant ...

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
set MyEndText to 0
repeat with Indice from 1 to 10
	GoToLog("Word In - " & Indice)
	set MyEndText to Word_InsertText(MyEndText, "Bonjour " & Indice, "Titre 1")
end repeat
 
------------------------------------------------------------
on Word_InsertText(myLength, myText, myStyle)
	set myText to (myText & return)
	tell application "Microsoft Word"
		tell active document
			set myRange to create range start myLength end myLength
			set content of myRange to myText
			set myRange to change end of range myRange by a story item extend type by selecting
			set style of myRange to myStyle
		end tell
	end tell
	set myLength to myLength + (length of myText)
	return myLength
end Word_InsertText
------------------------------------------------------------
 
------------------------------------------------------------
on GoToLog(msg)
	try
		do shell script "defaults read b"
	on error errorText
		set msg to msg & " " & (text 12 thru 23 of errorText)
	end try
	set the my_log to ((path to desktop) as text) & "journal.txt"
	try
		open for access file the my_log with write permission
		write (msg & return) to file the my_log starting at eof
		close access file the my_log
	on error
		try
			close access file the my_log
		end try
	end try
end GoToLog
------------------------------------------------------------
Mon petit soucis est le suivant.
Quand on regarde les temps de traitement dans le fichier log, on obtient :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
Word In - 1 09:02:46.698
Word In - 2 09:02:46.749
Word In - 3 09:02:49.777
Word In - 4 09:02:49.822
Word In - 5 09:02:49.863
Word In - 6 09:02:49.909
Word In - 7 09:02:49.954
Word In - 8 09:02:52.977
Word In - 9 09:02:53.021
Word In - 10 09:02:53.064
Et je me retrouve avec des temps de traitement pas trop mal, sauf à certain moment (en gras dans le texte) ou il me colle 3 secondes de délai sans savoir pourquoi ....

Est-ce pareil chez vous ?

Thais