csv anstelle xlsx
25.01.2022 13:39:01
Daniela
Ich komme mit dem Einlese Makro immer noch nicht weiter.
Nun werden mir anstelle von Excel Dateien, csv Dateien geschickt. Lese ich die CSV Datei ein, wird in den Zellen #Bezug! dargestellt.
Was muss ich in dem Makro alles umstellen, damit anstelle von XLSX, CSV erkannt wird?
Wer ist so lieb und kann mir einen Tipp geben?
Sub Einlesen ()
ActiveSheet.Unprotect Password:="*****"
Dim oMe As Worksheet, iZeile As Long, oDatei As Object
Dim oFS As Object, wbQuelle As Workbook, sBlatt As String
Set oMe = ThisWorkbook.ActiveSheet
Const sDateiPfad As String = "
\"
iZeile = 2
Application.ScreenUpdating = False
Set oFS = CreateObject("Scripting.FileSystemObject")
For Each oDatei In oFS.GetFolder(sDateiPfad).Files
If InStrRev(oDatei.Name, "xlsx") Then
sBlatt = "Tabelle1"
oMe.Cells(5, 2) = GetValue(sDateiPfad, oDatei.Name, sBlatt, Range("A2"))
oMe.Cells(4, 2) = GetValue(sDateiPfad, oDatei.Name, sBlatt, Range("B2"))
oMe.Cells(3, 7) = GetValue(sDateiPfad, oDatei.Name, sBlatt, Range("C2"))
oMe.Cells(12, 2) = GetValue(sDateiPfad, oDatei.Name, sBlatt, Range("D2"))
oMe.Cells(13, 2) = GetValue(sDateiPfad, oDatei.Name, sBlatt, Range("E2"))
iZeile = iZeile + 1
End If
Next
Set oMe = Nothing: Set wbQuelle = Nothing
ActiveSheet.Protect Password:="*****"
End Sub
Private Function GetValue(ByVal sPath As String, ByVal sFile As String, _
ByVal sSheet As String, oTarget As Object) As Variant
' Einen Wert aus einer Datei holen
On Error GoTo ErrorHandler
If Right$(sPath, 1) "\" Then sPath = sPath & "\"
GetValue = ExecuteExcel4Macro("'" & sPath & "[" & sFile & "]" & sSheet & "'!" _
& oTarget.Range("A1").Address(, , xlR1C1))
On Error GoTo ErrorHandler
If IsError(GetValue) Then
GetValue = ExecuteExcel4Macro("'" & sPath & "[" & sFile & "]" & "Feuil1" & "'!" _
& oTarget.Range("A1").Address(, , xlR1C1))
End If
Exit Function
ErrorHandler:
GetValue = CVErr(xlErrRef)
End Function
lg Daniela