Mon script seul fonctionne / le même exécuté en vba excel plante
Bonjour à tous!
Voilà un problème bien mystérieux : j'ai une macro vba excel qui crée un fichier script.
Si j'ouvre etle mets en route le fichier avec l'éditeur de script, le script fonctionne parfaitement.
Par contre, si je le mets en marche par une macro vba, il commence à fonctionner puis il plante.
Est-ce que quelqu'un a déjà eu ce genre de problème svp ?
Voici le code :
Code:
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
Sub gtime()
Dim str As String, str2 As String, Fichier As String, CR As String
CR = Chr$(13)
str = "to clickClassName(theClassName, elementnum)"
str = str & CR & "tell application ""Safari"""
str = str & CR & "do JavaScript ""document.getElementsByClassName('"" & theClassName & ""')["" & elementnum & ""].click();"" in document 1"
str = str & CR & "end tell"
str = str & CR & "end clickClassName"
str = str & CR & "tell application ""Safari"""
str = str & CR & "Activate"
str = str & CR & "open location ""https://www.gtimereport.com"""
str = str & CR & "Delay 5"
str = str & CR & "end tell"
str = str & CR & "clickClassName(""link"", 0)"
str = str & CR & "Delay 4"
str = str & CR & "clickClassName(""checkbox-container"", 0)"
str = str & CR & "Delay 0.5"
str = str & CR & "clickClassName(""checkbox-container"", 1)"
str = str & CR & "set theDate to ((current date) + 1 * days)"
str = str & CR & "set y to text -4 thru -1 of (""0000"" & (year of theDate))"
str = str & CR & "set m to text -2 thru -1 of (""00"" & ((month of theDate) as integer))"
str = str & CR & "set d to text -2 thru -1 of (""00"" & (day of theDate))"
str = str & CR & "set a to y & ""-"" & m & ""-"" & d as string"
str = str & CR & "tell application ""System Events"""
str = str & CR & "Delay 1"
str = str & CR & "keystroke tab"
str = str & CR & "Delay 1"
str = str & CR & "keystroke a"
str = str & CR & "Delay 1"
str = str & CR & "keystroke tab"
str = str & CR & "Delay 1"
str = str & CR & "keystroke a"
str = str & CR & "Delay 1"
str = str & CR & "end tell"
str = str & CR & "Delay 1"
str = str & CR & "to clickName(theName, elementnum)"
str = str & CR & "tell application ""Safari"""
str = str & CR & "do JavaScript ""document.getElementsByName('"" & theName & ""')["" & elementnum & ""].click();"" in document 1"
str = str & CR & "end tell"
str = str & CR & "end clickName"
str = str & CR & "clickName(""createExcel"", 0)"
MacScript (str)
Fichier = ThisWorkbook.Path & Application.PathSeparator & "gtimereport.scpt"
Open Fichier For Output As #1
Print #1, str
Close |
et le code pour l'exécuter :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
Sub GTime2()
Dim str2 As String, fichier As String
fichier = ThisWorkbook.Path & Application.PathSeparator & "gtimereport.scpt"
CR = Chr$(13)
str2 = "tell application ""Finder"""
str2 = str2 & CR & "Activate"
str2 = str2 & CR & "Delay 2"
str2 = str2 & CR & "run script file """ & fichier & """"
str2 = str2 & CR & "end tell"
MsgBox str2
MacScript (str2)
End Sub |