Live-Forum - Die aktuellen Beiträge
Datum
Titel
17.04.2024 18:57:33
17.04.2024 16:56:58
Anzeige
Archiv - Navigation
1204to1208
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Fehler 1004 bei Import Funktion

Fehler 1004 bei Import Funktion
NewtonZ4
Hallo Zusammen, Sepp,
eigentlich hat alles gefunzt, aber jetzt bekomme ich immer folgende Fehlermeldung.
Bitte um Hilfe...!
Fehler 1004
Die Blätter können von Excel nicht in die Zielarbeitsmappe eingefügt
werden, da sie eine geringere Anzahl von Zeilen und Spalten enthält als
die Quellarbeitsmappe. Zum Verschieben oder Kopieren der Daten in
die Zielarbeitsmappe können Sie die Daten auswählen und dann
mithilfe der Befehle 'Kopieren' und 'Einfügen' in die Blätter einer
anderen Arbeitsmappe einfügen
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
Sub ImportCSP()
Dim objWB As Workbook
Dim strCSP As String, strPath As String, strNewName As String
Dim intC As Integer, lngCalc As Long
On Error GoTo ErrExit
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
lngCalc = .Calculation
.Calculation = xlCalculationManual
End With
strPath = "H:\Alarmreports 2011\Import"
strPath = IIf(Right(strPath, 1) = "\", strPath, strPath & "\")
strCSP = Dir(strPath & "*.csp", vbNormal)
Do While strCSP ""
intC = 0
Set objWB = Workbooks.Open(strPath & strCSP)
objWB.Sheets(1).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
strNewName = strCSP
Do While SheetExist(strNewName)
intC = intC + 1
strNewName = strCSP & "(" & intC & ")"
Loop
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = strNewName
objWB.Close False
strCSP = Dir
Loop
ErrExit:
If Err.Number 0 Then
MsgBox "Fehler:" & vbTab & Err.Number & vbLf & vbLf & Err.Description, vbExclamation, "Fehler"
End If
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
.Calculation = lngCalc
End With
Set objWB = Nothing
End Sub
Private Function SheetExist(ByVal sheetName As String, Optional Wb As Workbook) As Boolean
Dim wks As Worksheet
On Error GoTo ERRORHANDLER
If Wb Is Nothing Then Set Wb = ThisWorkbook
For Each wks In Wb.Worksheets
If LCase(wks.Name) = LCase(sheetName) Then SheetExist = True: Exit Function
Next
ERRORHANDLER:
SheetExist = False
End Function

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: Fehler 1004 bei Import Funktion
03.03.2011 20:55:08
Josef

Hallo Stefan,
bleib das nächste Mal bitte im alten Thread.
Hab den Code angepasst, es werden nun nicht mehr die Tabellen kopiert, sondern nur die Zellen.
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

Sub importCSP()
  Dim objWB As Workbook
  Dim strCSP As String, strPath As String, strNewName As String
  Dim intC As Integer, lngCalc As Long
  
  On Error GoTo ErrExit
  
  With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .DisplayAlerts = False
    lngCalc = .Calculation
    .Calculation = xlCalculationManual
  End With
  
  strPath = "E:\Forum"
  
  strPath = IIf(Right(strPath, 1) = "\", strPath, strPath & "\")
  
  strCSP = Dir(strPath & "*.csp", vbNormal)
  
  Do While strCSP <> ""
    
    intC = 0
    
    Set objWB = Workbooks.Open(strPath & strCSP)
    
    ThisWorkbook.Worksheets.Add After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
    
    strNewName = Left(strCSP, Len(strCSP) - 4)
    
    Do While SheetExist(strNewName)
      intC = intC + 1
      strNewName = Left(strCSP, Len(strCSP) - 4) & "(" & intC & ")"
    Loop
    
    
    
    With ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
      objWB.Sheets(1).UsedRange.Copy .Range("A1")
      .Name = strNewName
      .Cells.UnMerge
      .Rows("1:14").Delete
      .Columns(1).Delete
    End With
    
    objWB.Close False
    
    strCSP = Dir
  Loop
  
  ErrExit:
  
  If Err.Number <> 0 Then
    MsgBox "Fehler:" & vbTab & Err.Number & vbLf & vbLf & Err.Description, vbExclamation, "Fehler"
  End If
  
  With Application
    .ScreenUpdating = True
    .EnableEvents = True
    .DisplayAlerts = True
    .Calculation = lngCalc
  End With
  
  Set objWB = Nothing
End Sub

Private Function SheetExist(ByVal sheetName As String, Optional Wb As Workbook) As Boolean
  Dim wks As Worksheet
  On Error GoTo ERRORHANDLER
  If Wb Is Nothing Then Set Wb = ThisWorkbook
  For Each wks In Wb.Worksheets
    If LCase(wks.Name) = LCase(sheetName) Then SheetExist = True: Exit Function
  Next
  ERRORHANDLER:
  SheetExist = False
End Function


Gruß Sepp

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige