running excel macro from another workbook

前端 未结 4 1392
独厮守ぢ
独厮守ぢ 2020-12-01 19:19

I have a macro that is on a server. I need to be able to run it from different workstations that connect to this server.

Currently I am doing:

Applic         


        
4条回答
  •  北海茫月
    2020-12-01 20:08

    If the macro you need to find relative macro path by using workbook path from which you run macro and you need to run several macros from the array list, the code below will help:

    Dim relativePath As String, programFileName As String
    Dim selectedProgramsFiles() As String, programsArrayLastIndex As Byte, I As Byte
    
    For I = 0 To programsArrayLastIndex 'Loop through all selected programs
        programFileName = selectedProgramsFiles(I)
        relativePath = ThisWorkbook.Path & "\" & programFileName
        Workbooks.Open Filename:=relativePath
    
        Application.Run ("'" & relativePath & "'!ModuleName.Main")
    
        Workbooks(programFileName).Activate
        ActiveWorkbook.Close SaveChanges:=False
    Next I 'For I = 0 To programsArrayLastIndex 'Loop through all selected program
    

提交回复
热议问题