Thanks for looking at my problem. I have a python script which is writing a new csv file in my current directory. I have make it python.exe using pyinstaller. What I am doing is, running this exe file using VBA form excel on a button click. Problem is after running exe using VBA my csv is saving in default documents folder instead of folder where my python.exe is. But If I run the python.exe directly without VBA then it's saving csv in my current directory. So how can I save csv in current directory after running python.exe using VBA
Here is my python code which creating new csv file:
csvfile = open("Mycsv" + '.csv', 'w')
cr = csv.writer(csvfile, dialect='excel')
I have also tried using: csvfile = open(os.getcwd() + "\Mycsv" + '.csv', 'w') But didn't worked.
Here is my VBA code:
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
Dim errorCode As Integer
wsh.Run Chr(34) & ThisWorkbook.path & "\python.exe" & Chr(34), windowStyle, waitOnReturn
python.exeas an argument. The python program has no way to know otherwise which directory your excel file was. It is an independent process.wsh.CurrentDirectory = ...before thewsh.Run ...