-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.vba
132 lines (88 loc) · 3.43 KB
/
macros.vba
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
Option Compare Database
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub download_all_20mn()
Dim curDate As Date
Dim url, cmd As String
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
'On initialise la date à aujourd'hui
curDate = Date
ChDir Application.CurrentProject.Path
For i = 0 To 3000
url = "http://pdf.20mn.fr/" & Format(curDate, "yyyy") & "/quotidien/" & Format(curDate, "yyyymmdd") & "_PAR.pdf"
cmd = "aria2c64.exe -d 20mn " & url
'Shell (cmd)
wsh.Run cmd, windowStyle, waitOnReturn
curDate = DateAdd("d", -1, curDate)
Next
End Sub
Sub pdf_to_txt()
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(Application.CurrentProject.Path & "\20mn")
Set fc = f.Files
ChDir Application.CurrentProject.Path
For Each f1 In fc
If Dir("txt/" & f1.Name & ".txt") = "" Then
'Ouverture du document
'Remplacer par le chemin d'adobe reader
Dim READERPath As String
READERPath = """C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"" "
Shell READERPath & "20mn\" & f1.Name, vbNormalFocus: DoEvents
Sleep 2000
'récupération du contenu dans le presse papier
SendKeys "^a", True
Sleep 2000
SendKeys "^c", True
Sleep 3000
'fermeture du document PDF
Shell "taskkill /f /IM AcroRd32*"
Sleep 1000
'puis on enregistre le contenu du presse papier dans un fichier txt
Shell "notepad.exe /W txt/" & f1.Name & ".txt", vbNormalFocus
Sleep 1000
SendKeys "{enter}", True
Sleep 500
SendKeys "^v", True
Sleep 500
SendKeys "^s", True
Sleep 500
SendKeys "%{F4}", True
Sleep 500
End If
Next
End Sub
Sub txt_to_database()
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(Application.CurrentProject.Path & "\txt")
Set fc = f.Files
ChDir Application.CurrentProject.Path
CurrentDb.Execute "DROP TABLE horoscopes"
CurrentDb.Execute "CREATE TABLE horoscopes (id AUTOINCREMENT, jour DATE, signe INTEGER, description TEXT(255));"
For Each f1 In fc
Dim day As Date
day = Mid(f1.Name, 7, 2) & "/" & Mid(f1.Name, 5, 2) & "/" & Mid(f1.Name, 1, 4)
'Ajouter la référence "Microsoft Scripting Runtime"
Dim fso As FileSystemObject: Set fso = New FileSystemObject
Set txtStream = fso.OpenTextFile("txt/" & f1.Name, ForReading, False, TristateTrue)
Do While Not txtStream.AtEndOfStream
Dim line As String
line = txtStream.ReadLine
If line = "HOROSCOPE" Then
For signe = 1 To 12
Dim content As String
'nom du signe
txtStream.ReadLine
content = ""
For ligne = 1 To 3
content = content & Trim(txtStream.ReadLine) & " "
Next
content = RTrim(content)
CurrentDb.Execute "INSERT INTO horoscopes (jour, signe, description) VALUES (""" & day & """," & signe & ",""" & content & """)"
Next
End If
Loop
txtStream.Close
Next
End Sub