A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
hello , Thank you very much for your suggestion and your time !
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I want to run a macro that searches for another file within the current folder. Both the macro and the folder are located on a network drive, outside of my local PC. I recently discovered that when I execute the macro, Excel actually copies the macro-enabled file to a local directory, runs the macro, and then syncs the results back to the network.
The problem occurs during this copying process: when the code executes, the dynamic path changes, and the code fails because it no longer operates within the current network folder.
Is there a way to configure Excel to run the macro directly from the network without creating a local copy?
Thank you for your help
V.
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
hello , Thank you very much for your suggestion and your time !
I have tried and cannot make it work. I'd suggest you create a new thread on Stack Overflow which is special channel to handle VBA related question.
Mmembers and engineers over there are proficient in the knowledge of this kind of concerns. They will focus on the specific situation and provide specific suggestions for you.
Thank you for your understanding.
Hello,
Actually you can create a project where a simple code VBA (macro button) that take a dynamic path to run a python file. And the python file has to go in the excel to take all the information. Here is an example (created on chatgpt) you can try : python file (used for an addition) :
import pandas as pd
def addition_from_excel():
# Chemin dynamique vers le fichier Excel (relatif à l'emplacement du script)
excel_path = "data.xlsx"
# Lire les données du fichier Excel
df = pd.read\_excel(excel\_path)
# Supposons que les colonnes A et B contiennent les nombres à additionner
if 'Nombre1' in df.columns and 'Nombre2' in df.columns:
df['Somme'] = df['Nombre1'] + df['Nombre2']
# Écrire le résultat dans le fichier Excel
df.to\_excel(excel\_path, index=False)
print("Les sommes ont été calculées et enregistrées dans le fichier Excel.")
else:
print("Les colonnes Nombre1 et Nombre2 sont introuvables dans le fichier Excel.")
if __name__ == "__main__":
addition_from_excel()
and here is the macro code you can put in a button macro:
Sub RunPythonScript()
Dim objShell As Object
Dim pythonExe As String
Dim scriptPath As String
' Chemin dynamique : modifiez en fonction de votre configuration
pythonExe = "python" ' Suppose que Python est dans le PATH
scriptPath = ThisWorkbook.Path & "\addition.py"
' Exécuter le script Python
Set objShell = CreateObject("WScript.Shell")
objShell.Run pythonExe & " " & Chr(34) & scriptPath & Chr(34), 1, True
MsgBox "Script Python exécuté !", vbInformation
End Sub
you will see that the code actually works on your machine but when you put this project on a network. that doens't work. -> the code is copied on the machine , run on the machine and after the result is injected in the network. And I would like to use a dynamic path.
Could you share the code you are using? Then I can reproduce your issue to correct your code.
Please understand that initial reply may not always immediately resolve the issue due to limited information. However, with your help and more detailed information, we can work together to find a solution.