Copy/Paste v.Bildern: Laufzeitfehler 1004: Die PasteSpecial.
03.11.2023 14:13:18
deborah
ich bin neu hier und habe mich mithilfe von chatGPT an VBA getraut. Bitte keine Witze machen, ich habe erst vor paar Wochen mit VBA angefangen.
Nun zum Problem: Ich habe im Blatt «Symbols» verschiedene Bilder/Symbole, die im neu-erstellten Blatt «newVSM», je nach Dateninput im Blatt «Data», eingefügt werden sollen.
Wenn ich den Code ausführe, geht er die Daten durch und ersetzt diese durch Bilder/Symbole im neu erstellten Blatt. Von 5 Versuchen, klappt der Code ca. 3x. Bei den anderen 2x bleibt er bei einem «newVSMsheet.Rane(XX).PasteSepcial xlPasteAll» Teil hängen. Ganz per Zufall, immer an einer anderen Stelle
Die Symbole sind richtig «verlinkt», was ja auch die die Versuche bestätigen, welche funktionieren.
Weiss jemand, warum der Code jedoch ab und zu hängen bleibt? Hier der Code:
Sub GenerateNewVSM()
Dim flowDataSheet As Worksheet
Dim newVSMsheet As Worksheet
Dim symbolsSheet As Worksheet
Dim lastRow As Long
[
]
' Create a new "new VSM" sheet
Set newVSMsheet = Sheets.Add(After:=Sheets(Sheets.Count))
newVSMsheet.Name = "new VSM"
Application.CutCopyMode = False
symbolsSheet.Shapes("Group 33").Copy ' add information flow symbol
newVSMsheet.Range("A4").PasteSpecial xlPasteAll ' Paste the shape into cell A4 on newVSMsheet
Application.CutCopyMode = False
symbolsSheet.Shapes("Group 7237").Copy ' add weekly plan symbol
newVSMsheet.Range("A8").PasteSpecial xlPasteAll ' Paste the shape into cell A8 on newVSMsheet
Application.CutCopyMode = False
symbolsSheet.Shapes("Group 7236").Copy ' Add push symbol
newVSMsheet.Range("A13").PasteSpecial xlPasteAll ' Paste the shape into cell A13 on newVSMsheet
Application.CutCopyMode = False
symbolsSheet.Shapes("Group 13").Copy ' Add pull symbol
newVSMsheet.Range("A15").PasteSpecial xlPasteAll ' Paste the shape into cell A15 on newVSMsheet
Application.CutCopyMode = False
symbolsSheet.Shapes("Group 5").Copy ' Add push symbol
newVSMsheet.Range("A18").PasteSpecial xlPasteAll ' Paste the shape into cell A18 on newVSMsheet
Application.CutCopyMode = False
symbolsSheet.Shapes("Group 1").Copy ' Add kanban cards symbol
newVSMsheet.Range("A23").PasteSpecial xlPasteAll ' Paste the shape into cell A23 on newVSMsheet
Application.CutCopyMode = False
symbolsSheet.Shapes("Picture 28").Copy ' Add flt symbol
newVSMsheet.Range("A29").PasteSpecial xlPasteAll ' Paste the shape into cell A29 on newVSMsheet
Application.CutCopyMode = False
symbolsSheet.Shapes("Picture 225").Copy ' Add agv symbol
newVSMsheet.Range("A32").PasteSpecial xlPasteAll ' Paste the shape into cell A32 on newVSMsheet
Application.CutCopyMode = False
symbolsSheet.Shapes("Picture 63").Copy ' Add manual truck symbol
newVSMsheet.Range("A36").PasteSpecial xlPasteAll ' Paste the shape into cell A36 on newVSMsheet
Application.CutCopyMode = False
symbolsSheet.Shapes("Picture 9").Copy ' Add milkrun truck symbol
newVSMsheet.Range("A39").PasteSpecial xlPasteAll ' Paste the shape into cell A39 on newVSMsheet
Application.CutCopyMode = False
symbolsSheet.Shapes("Group 7232").Copy ' Add kaizen symbol
newVSMsheet.Range("A43").PasteSpecial xlPasteAll ' Paste the shape into cell A4 on newVSMsheet
Application.CutCopyMode = False
symbolsSheet.Shapes("Group 37").Copy ' Add supplier symbol
newVSMsheet.Range("C3").PasteSpecial xlPasteAll ' Paste the shape into cell A4 on newVSMsheet
Application.CutCopyMode = False
symbolsSheet.Shapes("Group 7318").Copy ' Add supplier arrow
newVSMsheet.Range("C9").PasteSpecial xlPasteAll ' Paste the shape into cell A4 on newVSMsheet
Application.CutCopyMode = False
[...]
Ich weiss, der Code sieht ziemlich doof, nicht schön und nicht professionell aus, aber für mich ist er verständlich.
Danke!
Deborah