Skip to content

Commit 1e29e35

Browse files
authored
Create ExcelRunPythonCMD.py
1 parent 8697ae2 commit 1e29e35

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

ExcelRunPythonCMD.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Option Explicit
2+
3+
' http://www.vitoshacademy.com/run-python-functm-excel-with-vba/
4+
' Library - Microsoft Scripting Runtime
5+
6+
Sub TestMe()
7+
Dim path As String: path = "C:\Python\"
8+
Dim pathExe As String
9+
Dim i As Long
10+
Dim txtStream As TextStream
11+
Dim fso As New FileSystemObject
12+
Dim fileName As String
13+
14+
Columns("C:D").Clear
15+
For i = 1 To 8
16+
17+
fileName = "file" & i & ".txt"
18+
pathExe = path & "CodeForces.py" & " """ & Cells(i, 1) & """ >" & path & fileName
19+
Shell "cmd.exe /S /c " & pathExe
20+
21+
Application.Wait Now + #12:00:01 AM#
22+
Set txtStream = fso.OpenTextFile(path & fileName)
23+
Cells(i, 3) = txtStream.ReadLine
24+
txtStream.Close
25+
'Kill path & fileName
26+
27+
If Cells(i, 3) = Cells(i, 2) Then Cells(i, 4) = "Pass..."
28+
29+
Next i
30+
31+
End Sub
32+
33+
34+

0 commit comments

Comments
 (0)