0

I have the following python script that deletes the blank line that appears when exporting an excel sheet as .txt and moves it to a different path

fd=open("D:\\Arturo\\Documentos\\8 Semestre\\Tutoreo\\Exportación como TXT VBA\\Trigger.txt","r")
d=fd.read()
fd.close()
m=d.split("\n")
s="\n".join(m[:-1])

fd=open("D:\\Arturo\\Documentos\\8 Semestre\\Tutoreo\\Exportación como TXT VBA\\Trigger.txt","w+")
for i in range(len(s)):
    fd.write(s[i])
fd.close()

import shutil
original = "D:\\Arturo\\Documentos\\8 Semestre\\Tutoreo\\Exportación como TXT VBA\\Trigger.txt"
target = "C:\\Users\\artur\\Desktop\\Trigger\\Trigger.txt"

shutil.copyfile(original, target)

and this is how I call the script in vba

Sub eliminar_linea_py()

    Dim objShell As Object
    Dim PythonExe, PythonScript As String
    Set objShell = VBA.CreateObject("Wscript.Shell")
    PythonExe = """C:\Users\artur\AppData\Local\Programs\Python\Python310\python.exe""" 
    PythonScript = "C:\Users\artur\Desktop\py4e\remove_last_line.py" 
    objShell.Run PythonExe & PythonScript
    
End Sub

I'm working in the company computer and don't have admin permissions, when I try to run python script with VBA it doesn't work, how ever if I run the python script through command window it works perfectly, any idea of why this is happening and how could it be solved.

I have tried it in my personal laptop and vba its able to run the script without any issues.

Sorry for the long text, thank you for you time.

2
  • Maybe try a slightly different approach so you can see any errors which might be occurring: stackoverflow.com/a/71446266/478884 Commented Apr 8, 2022 at 23:49
  • thanks Tim, I'll get back next week and update Commented Apr 9, 2022 at 0:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.