-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathExcelRunPythonCMD.py
More file actions
34 lines (23 loc) · 868 Bytes
/
ExcelRunPythonCMD.py
File metadata and controls
34 lines (23 loc) · 868 Bytes
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
Option Explicit
' http://www.vitoshacademy.com/run-python-funct…m-excel-with-vba/
' Library - Microsoft Scripting Runtime
Sub TestMe()
Dim path As String: path = "C:\Python\"
Dim pathExe As String
Dim i As Long
Dim txtStream As TextStream
Dim fso As New FileSystemObject
Dim fileName As String
Columns("C:D").Clear
For i = 1 To 8
fileName = "file" & i & ".txt"
pathExe = path & "CodeForces.py" & " """ & Cells(i, 1) & """ >" & path & fileName
Shell "cmd.exe /S /c " & pathExe
Application.Wait Now + #12:00:01 AM#
Set txtStream = fso.OpenTextFile(path & fileName)
Cells(i, 3) = txtStream.ReadLine
txtStream.Close
'Kill path & fileName
If Cells(i, 3) = Cells(i, 2) Then Cells(i, 4) = "Pass..."
Next i
End Sub