Sorry....... fordi filnavnene slet ikke bliver fyldt i den Collection. Indsæt første linie i denne Sub.
Public Sub OpenFiles() FileNamesToCollection For mlFile = 1 To gcolFileNames.Count Application.Workbooks.Open msPATH & gcolFileNames(mlFile) Next mlFile End Sub
Så er jeg på pinden igen og har fået tid til at få mit lille projekt færdig.
Jeg får stadig fejlen: Koden kan ikke udføres i pausetilstand.
Det jeg har gjort er, at jeg har overskrevet makroen "Public Sub OpenFiles()" med det du skrive dit indlæg den 28/2 kl. 18:35: Public Sub OpenFiles() FileNamesToCollection For mlFile = 1 To gcolFileNames.Count Application.Workbooks.Open msPATH & gcolFileNames(mlFile) Next mlFile End Sub Hvad har jeg gjort forkert?
Hvis ellers du retter msPATH og filnavne korrekt til, så virker det altså. Jeg har lige testet.
Option Explicit
Public gcolFileNames As Collection Private Const msPATH As String = "C:\VBA-TEST\" Private mlFile As Long
Public Sub OpenFiles() FileNamesToCollection For mlFile = 1 To gcolFileNames.Count Application.Workbooks.Open msPATH & gcolFileNames(mlFile) Next mlFile End Sub
Public Sub CloseFiles() For mlFile = 1 To gcolFileNames.Count Application.Workbooks(gcolFileNames(mlFile)).Close SaveChanges:=True Next mlFile End Sub
Private Sub FileNamesToCollection() Set gcolFileNames = New Collection
With gcolFileNames .Add "1.xls" .Add "2.xls" .Add "3.xls" .Add "4.xls" .Add "5.xls" .Add "6.xls" .Add "7.xls" .Add "8.xls" .Add "9.xls" .Add "10.xls" .Add "11.xls" .Add "12.xls" .Add "13.xls" .Add "14.xls" .Add "15.xls" End With End Sub
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.