Jeg har brugt denne løsning
Sub GetDataFromAllSheets()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim Optælningskonstant As Integer
DeleteRows (2)
Call GetDataDemo("livredderrapport 2012 Kolding.xlsm", 0)
Optælningskonstant = Cells(2, 21)
Call GetDataDemo("livredderrapport 2012 Odense.xlsm", Optælningskonstant)
Optælningskonstant = Cells(2, 21)
Call GetDataDemo("livredderrapport 2012 Aalborg.xlsm", Optælningskonstant)
Optælningskonstant = Cells(2, 21)
Call GetDataDemo("livredderrapport 2012 Århus.xlsm", Optælningskonstant)
End Sub
'you can extract data from a closed file by using an
'XLM macro. Credit for this technique goes to John
'Walkenback >
http://j-walk.com/ss/excel/tips/tip82.htm Sub GetDataDemo(FileNameInput, InputInteger)
Dim FilePath$, Row&, Column&, Address$
Dim NumRows As Integer, FileName As String
'change constants & FilePath below to suit
'***************************************
FileName = FileNameInput
Const SheetName$ = "Vagtdata"
FilePath = ActiveWorkbook.Path & "\"
'****************************** Getting number of rows
Application.ScreenUpdating = False
If Dir(FilePath & FileName) = Empty Then
MsgBox "The file " & FileName & " was not found", , "File Doesn't Exist"
Exit Sub
End If
Address = Cells(2, 1).Address
NumRows = GetData(FilePath, FileName, "Data Baggrundskode", Address)
'*******************************
Const NumColumns& = 14
Const NumStart& = 4
'***************************************
DoEvents
Application.ScreenUpdating = False
If Dir(FilePath & FileName) = Empty Then
MsgBox "The file " & FileName & " was not found", , "File Doesn't Exist"
Exit Sub
End If
For Row = 1 To NumRows
For Column = 1 To NumColumns
Address = Cells(Row + NumStart, Column).Address
Cells(Row + 1 + InputInteger, Column) = GetData(FilePath, FileName, SheetName, Address)
Next Column
Next Row
ActiveWindow.DisplayZeros = False
Cells(2, 21) = NumRows + InputInteger
End Sub
Private Function GetData(Path, File, Sheet, Address)
Dim Data$
Data = "'" & Path & "[" & File & "]" & Sheet & "'!" & _
Range(Address).Range("A1").Address(, , xlR1C1)
GetData = ExecuteExcel4Macro(Data)
End Function
Sub DeleteRows(ByVal HeaderRow As Long)
'''''''''''''''''''''''''''''''''''''''''
'Deletes all Rows starting from HeaderRow
'to the last row of the Worksheet
'''''''''''''''''''''''''''''''''''''''''
'Set the range to be deleted
Dim rngRange As Range
With Sheets("Vagtdata")
Set rngRange = .Range _
(.Cells(HeaderRow, 1), .Cells(.Rows.Count, 1)).EntireRow
End With
'Delete this range
rngRange.Delete
End Sub