Die AddComment-Syntax funktioniert auf dem ersten ausgewählten Blatt in der Arbeitsmappe, aber für die nächste gibt mir diesen Fehler: Fehler 1004 "anwendungsdefinierte oder objektdefinierte Fehler". Ich weiß nicht, warum abstürzt, wenn mehrere Blätter ausgewählt wurden und nur für das erste ausgewählte funktioniert. Hat jemand eine Idee?AddComment auf mehreren Blättern vba Excel
If selectedSheet.Cells(7, columnIndex).value <> 100 Then
selectedSheet.Cells(7, columnIndex).Interior.ColorIndex = 3
If standardReportFilePath <> "" Then 'not using the Standard Report Evalution algorithm
If VerifyStandardReportFile(selectedSheet.Name, selectedSheet.Cells(1, columnIndex).value, wbk, amplitude, missingCrashes) = True Then
selectedSheet.Cells(1, columnIndex).Interior.ColorIndex = 36 ' color the crash cell with yellow
Set rng = selectedSheet.Cells(1, columnIndex)
If rng.Comment Is Nothing Then
**rng.AddComment "In Standard Report this crash starts to deploy from " & CStr(amplitude) & " amplitude"**
Else
rng.Comment.Text "In Standard Report this crash starts to deploy from " & CStr(amplitude) & " amplitude"
End If
End If
End If
End If
End If
Ein alternativer Code, der das Problem anzeigt. (Führen Sie dies mit drei leeren Arbeitsblatt in einer neuen Arbeitsmappe.):
Sub test()
Dim ws As Worksheet
Dim Rng As Range
'Running code with a single sheet selected
Worksheets("Sheet1").Select
'Code that shows issue - this will work
Set ws = Worksheets("Sheet2")
Set Rng = ws.Cells(1, 1)
If Rng.Comment Is Nothing Then
Rng.AddComment "xxx"
End If
'Get rid of comment again
Rng.Comment.Delete
'Running code with multiple sheets selected
Worksheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
'Code that shows issue - will crash on the "AddComment"
Set ws = Worksheets("Sheet2")
Set Rng = ws.Cells(1, 1)
If Rng.Comment Is Nothing Then
Rng.AddComment "xxx"
End If
End Sub
Versuchen Sie, '' Activate' selectedSheet' jedes Mal, wenn Sie ein Set ein neues. –
tat ich. Kein Erfolg :( –
Eine andere Idee, vielleicht ist es ein Problem mit "Amplitude" Sorry für das nicht zu überprüfen, aber ich kann nicht auf meinen Computer atm zugreifen. –