Is het mogelijk om met behulp van VBA een Macro te starten uit een ander bestand?
Situatie:
Ik heb twaalf Excel bestanden met ieder zn eigen macro
Ik wil elk bestand om de beurt openen om de Macro uit het bestand te starten.
Ik had zelf zoiets in gedachten:
Door middel van deze code wordt het bestand wel geopend alleen draait de macro niet, heeft iemand hier een oplossing voor?
Situatie:
Ik heb twaalf Excel bestanden met ieder zn eigen macro
Ik wil elk bestand om de beurt openen om de Macro uit het bestand te starten.
Ik had zelf zoiets in gedachten:
Code:
Sub Test()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook
Dim lastrow As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
Sheets("Blad1").Select
On Error Resume Next
Set wbCodeBook = ThisWorkbook
With Application.FileSearch
.NewSearch
.LookIn = "C:\"
.FileType = msoFileTypeExcelWorkbooks
.Filename = "Bestand1.xls"
If .Execute > 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through all.
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
Sheets("Totalen").Select
Windows("Bestand1.xls").Activate
Application.Run ("Bestand1.xls!StartMacro").
wbResults.Close SaveChanges:=True
Next lCount
End If
End With
End Sub
Door middel van deze code wordt het bestand wel geopend alleen draait de macro niet, heeft iemand hier een oplossing voor?
Laatst bewerkt: