Dies ist mein Code zum Kopieren eines Blattes auf ein neues Blatt. Wenn ich das Programm mit Breakpoint auf Workbooks.Open(path)
lief, funktionierte es richtig, aber wenn ich ohne den Haltepunkt lief, öffnete es einfach die Arbeitsmappe, ohne ein Blatt zu erstellen.
Ich habe mein Bestes versucht, um den Fehler zu beheben, aber ich konnte nicht das gewünschte Ergebnis erhalten.VBA Excel-Programm funktioniert nur mit Haltepunkt
Sub CopyCat()
Dim ws As Worksheet
Dim no As Integer
Set ws1 = ActiveSheet
Dim path As String
temp_name = InputBox("Enter the Sheet No to be Created", "Enter the Value")
For Loop1 = 1 To ws1.UsedRange.Rows.Count
path = Application.ActiveWorkbook.path & "\" & Application.WorksheetFunction.Trim(Trim(ws1.Cells(Loop1, 1).Value)) & " " & ws1.Cells(Loop1, 2).Value & ".xlsx"
Set wb1 = Workbooks.Open(path)
'ListBox1.AddItem wb.Name
temp_name = "Sheet" & temp_name
'error1 = CheckSheet(wb1, temp_name)
'If (error1 <> True) Then
ws1.Cells(4, 1).Value = "Created" & CStr(Loop1)
Set ws = wb1.Worksheets(Sheets.Count)
ws.Copy After:=wb1.Sheets(Sheets.Count)
Set ws = ActiveSheet
ws.Name = temp_name
'Call PageSetting
wb1.Close SaveChanges:=True
ws1.Cells(4, 1).Value = "Created Done" & CStr(Loop1)
'Else
'wb1.Close SaveChanges:=True
'End If
Next Loop1
End Sub
Function CheckSheet(ByVal wb As Workbook, ByVal sSheetName As String) As Boolean
Dim oSheet As Excel.Worksheet
Dim bReturn As Boolean
For Each oSheet In wb.Sheets
If oSheet.Name = sSheetName Then
bReturn = True
Exit For
End If
Next oSheet
CheckSheet = bReturn
End Function
Sie Fehler bekommen Sie? Welcher [Fehlerbehandlungsmodus] (http://stackoverflow.com/q/12687105/11683) ist eingestellt? – GSerg
Kein Fehler, den ich habe. Es öffnete einfach das Blatt, während ich es lief. Aber als ich dieses Modul kopiert und ein neues Modul mit demselben Code erstellt habe, lief es perfekt. Ich weiß nicht, warum es passiert ist, aber es hat funktioniert. –
Es ist noch nicht gelöst –