Share via

Macro file on network

Anonymous
2024-12-20T12:27:44+00:00

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.

Microsoft 365 and Office | Excel | For business | Windows

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.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2024-12-24T07:03:58+00:00

    hello , Thank you very much for your suggestion and your time !

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2024-12-24T06:57:07+00:00

    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.

    Stack Overflow

    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.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2024-12-23T07:42:21+00:00

    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.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2024-12-20T16:54:00+00:00

    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.

    Was this answer helpful?

    0 comments No comments