code hat fehler...wer hilft?
16.05.2004 17:32:19
martin
habe einen Code gefunden, wie man angeblich Daten aus allen Dateien eines Ordners zusammenfassen kann. Habe den Code eingegeben und bekomm jetzt folgende Fehlermeldung: Fehler beim Kompilieren - Nach End Sub , End Property oder End
Function können nur Kommentare stehen.
Hab den Code aber doch nur so übernommen. Kann da ma einer reinschauen? Wäre ganz nett.
Hier kommt der Code:
Sub Datensammeln()
Dim wks As Worksheet
Dim fs As FileSearch
Dim rng As Range
Dim iCounter As Integer, iRow As Integer
Dim sMsg As String, sDir As String
Application.ScreenUpdating = False
Application.EnableEvents = False
On Error GoTo ERRORHANDLER
sMsg = "Wählen Sie bitte einen Ordner aus:"
sDir = GetDirectory(sMsg)
If sDir = "" Then Exit Sub
Set wks = ActiveSheet
iRow = 3
Set fs = Application.FileSearch
With fs
.LookIn = sDir
.FileType = msoFileTypeExcelWorkbooks
.Execute
For iCounter = 1 To .FoundFiles.Count
Workbooks.Open_
FileName:=.FoundFiles(iCounter), _
updatelinks:=False
wks.Cells(iRow - 2, 1) .Value = ActiveWorkbook.Name & ":"
Set rng = RealLastCell(ActiveSheet)
Set rng = Range(Cells(1, 1), rng)
rng.Copy wks.Cells(iRow, 1)
iRow = iRow + rng.Rows.Count + 3
Application.CutCopyMode = False
ActiveWorkbook.Close savechanges:=False
Next iCounter
End With
ERRORHANDLER:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
StandardModule: basFunctions
Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Declare
Function SHGetPathFromIDList Lib "shell32.dll" _ an dieser
Alias "SHgetPathFromIDListA" (ByVal pidl As Long, _ Stelle ist
ByVal pszPath As String) As Long der Fehler
Declare
Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Function GetDirectory(Optional msg) As String
Dim bInfo As BROWSEINFO
Dim Path As String
Dim r As Long, x As Long, pos As Integer
bInfo.pidlRoot = 0&
If IsMissing(msg) Then
bInfo.lpszTitle = msg
End If
bInfo.ulFlags = &H1
x = SHBrowseForFolder(bInfo)
Path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal Path)
If r Then
pos = InStr(Path, Chr$(0))
GetDirectory = Left(Path, pos - 1)
Else
GetDirectory = ""
End If
End Function
Function RealLastCell(TheSheet As Worksheet) As Range
Dim ExcelLastCell As Range
Dim Row§, Col§, LastRowWithDate§, LastColWithData§
Application.ScreenUpdating = False
Set ExcelLastCell = TheSheet.Cells.SpecialCells(xLastCell)
LastRowWithData = ExcelLastCell.Row
Do While Application.CountA(TheSheet.Rows(Row)) = 0 And Row <> 1
Row = Row - 1
Loop
LastRowWithData = Row
LastColWithData = ExcelLastCell.Column
Col = ExcelLastCell.Column
Do While Application.CountA(TheSheet.Columns(Col)) = 0 And Col <> 1
Col = Col - 1
Loop
LastColWithData = Col
Set RealLastCell = TheSheet.Cells(Row, Col)
End Function
End Function
Vielen Dank schon mal,
Martin