Excel 2010 Kommentar mit Bild - Seitenverhältnis Sperren

  • Excel

Es gibt 8 Antworten in diesem Thema. Der letzte Beitrag () ist von Zoe4711.

    Excel 2010 Kommentar mit Bild - Seitenverhältnis Sperren

    Hallo Leute
    Ich habe ein kleines Problem, und zwar habe ich ein ein Excel-Sheet mit mehreren 1000 Kommentaren (zu viele um alles von Hand zu machen.) Nun haben alle Kommentare ein Bild als Hintergrund, aber das Seitenverhältniss sollte gesperrt sein. (Das wäre, wenn man es von Hand macht die Checkbox unter: Kommentar Formatieren -> Farben und Linien -> Das Farb Dropdown -> Fülleffekte -> Grafik -> Seitenverhältnis sperren.
    Kann ich diese Checkbox irgendwie per VBA parameter setzten? Der Makro-Recorder hat mir leider auch nicht geholfen.

    Vielen Dank für Hilfe
    Apple987123
    Guten Tag,

    ich stehe vor dem gleichen Problem wie apple987123 vor 5 Jahren. Ich suche genau wie er VBA Parameter, mit denen ich die Wege automatisieren kann, da es sehr viele Kommentarfelder sind. Es wäre super, wenn da jemand helfen könnte!

    Ansonsten: Ich arbeite an einer Excel-Tabelle, die Prüfgeräte auflistet. Dabei soll man ohne externe Fenster ein Bild des jeweiligen Gerätes sehen können. Bisher ist mir nur die Funktion mit dem Kommentarfeld und anschließender Hinterlegung des Hintergrundes mit einem Bild bekannt.

    Wenn jemand eine andere/bessere Lösung kennt, mit der ich eine Miniatur-Vorschau eines Bildes in Excel anzeigen kann, wäre ich auch sehr dankbar! Denn wirklich sauber ist diese Lösung auch nicht gerade.

    Danke für eure Hilfe,

    Stefan
    Wenn ein Makro aufgezeichnet wird, aber bestimmte Abläufe sich im Makro nicht wiederfinden, dann bedeutet das schlicht und ergreifend, dass es dafür keine VBA-Unterstützung gibt.

    "Jay Freedman" schrieb:


    office-forums.com/threads/lock…tio.1779129/#post-5533033

    Unfortunately, you're correct. There are far too many cases of controls in
    built-in dialogs that have no support in VBA. In each release the MVPs have
    asked again to have this fixed, but so far without success.


    (....)

    --
    Regards,
    Jay Freedman
    Microsoft Word MVP
    Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Zoe4711“ () aus folgendem Grund: redaktionelle Änderungen

    Zoe4711 schrieb:

    Wenn ein Makro aufgezeichnet wird, aber bestimmte Abläufe sich im Makro nicht wiederfinden, dann bedeutet das schlicht und ergreifend, dass es dafür keine VBA-Unterstützung gibt.

    Wer hat dich denn zu dieser Aussage bewegt?
    Der Makrorecorder kommt nicht an alle Dinge dran, vieles kann man aber doch verändern.
    NB. Es ist doch schön, wenn man lesbare Namen vergibt. Siehe auch [VB.NET] Beispiele für guten und schlechten Code (Stil).

    Eine "lustige" Sache mit .LockAspectRatio = msoTrue

    apple987123 schrieb:

    Hallo Leute
    Ich habe ein kleines Problem, und zwar habe ich ein ein Excel-Sheet mit mehreren 1000 Kommentaren (zu viele um alles von Hand zu machen.) Nun haben alle Kommentare ein Bild als Hintergrund, aber das Seitenverhältniss sollte gesperrt sein. (Das wäre, wenn man es von Hand macht die Checkbox unter: Kommentar Formatieren -> Farben und Linien -> Das Farb Dropdown -> Fülleffekte -> Grafik -> Seitenverhältnis sperren. vb-paradise.de/index.php/Attachment/13092/
    Kann ich diese Checkbox irgendwie per VBA parameter setzten? Der Makro-Recorder hat mir leider auch nicht geholfen.

    Vielen Dank für Hilfe
    Apple987123

    Wird ein Bild in ein Kommentar eingefügt, dann nimmt das Bild die Größe des Kommentars an. Danach ist das Bild bereits verzerrt.

    Soll die Verzerrung des Bildes verhindert werden, ist folgende Vorgehensweise notwendig:

    - Nach Auswahl des Bildes muss das Seitenverhältnis des Bildes berechnet werden
    - Mit dem Seitenverhältnis des Bildes muss das Kommentar so verändert werden, dass seine Form das Seitenverhältnis des Bildes annimmt
    - Wird das Bild in das Kommentar eingefügt - das das Seitenverhältnis des Bildes hat - wird das Bild nicht verzerrt
    - Erst jetzt muss das Seitenverhältnis des Kommentars gesperrt werden.

    Es ist nicht möglich das Seitenverhältnis des Bildes per VBA zu sperren, das in ein Kommentar eingefügt wird. Der Makrorecorder zeichnet das Setzen des Häkchens bei "Bildseitenverhältnis sperren" nicht auf.

    Visual Basic-Quellcode

    1. Sub insert_userpicture_in_comments()
    2. '** Dimensionierung der Variablen
    3. Dim rngZelle As Range
    4. Dim strFilename As Variant
    5. Dim strFilter As String
    6. Dim ScaleValue As Single
    7. Dim ScaleValue2 As Single
    8. Dim objPic As IPictureDisp
    9. Dim Source As String
    10. Dim i As Integer
    11. If ActiveSheet.Comments.Count = 0 Then
    12. MsgBox "No comments in entire sheet"
    13. Exit Sub
    14. End If
    15. 'Dateiauswahl filtern
    16. strFilter = "JPG Files (*.jpg), *.jpg" _
    17. & ", GIF Files (*.gif), *.gif" _
    18. & ", Bitmaps (*.bmp), *.bmp" _
    19. & ", WMF Files (*.wmf), *.wmf"
    20. ' Dialogfenster zur Auswahl eines Bildes öffnen
    21. strFilename = Application.GetOpenFilename(strFilter)
    22. DoEvents
    23. ' Wenn kein Bild ausgewählt wurde, Prozedur beenden
    24. If strFilename = False Then GoTo LabelA
    25. Source = (CStr(strFilename))
    26. DoEvents
    27. ' Set objPic = LoadPicture(Bild)
    28. Set objPic = LoadPicture(Source)
    29. DoEvents
    30. With objPic
    31. ScaleValue = .Width / .Height
    32. End With
    33. If MsgBox(ScaleValue, vbOKCancel) = vbCancel Then GoTo LabelA
    34. Application.CutCopyMode = False
    35. DoEvents
    36. Application.ScreenUpdating = False
    37. Application.Calculation = xlCalculationManual
    38. '** Alle markierten rngZellen durchlaufen
    39. For Each rngZelle In Selection.Cells
    40. With rngZelle
    41. If Not .Comment Is Nothing Then
    42. 'Insert The Image and Resize
    43. With .Comment.Shape
    44. .LockAspectRatio = msoFalse
    45. .Width = 150
    46. ' .Width = ScaleValue * .Height
    47. .Height = .Width / ScaleValue
    48. .Fill.UserPicture strFilename
    49. DoEvents
    50. .LockAspectRatio = msoTrue
    51. ScaleValue2 = .Width / .Height
    52. i = i + 1
    53. Debug.Print i; rngZelle.Address; ScaleValue; ScaleValue2
    54. End With
    55. End If
    56. End With
    57. Next rngZelle
    58. LabelA:
    59. Application.Calculation = xlCalculationAutomatic
    60. Application.ScreenUpdating = True
    61. On Error GoTo 0
    62. End Sub


    Edit:

    Achtung: Eine "lustige" Sache mit .LockAspectRatio = msoTrue ist die folgende:

    Die Standardform eines Kommentars ist ein Rechteck. In jeder Ecke und in der Mitte jeder Seite ist ein kleiner Kreis zu sehen, an dem gezogen, sich die Form des Rechtecks verändern lässt.

    Wenn .LockAspectRatio = msoTrue benutzt wird, ist das Seitenverhältnis nur gesperrt, wenn die Form des Kommentars an den Ecken gezogen wird.

    Das Seitenverhältnis lässt sich jedoch ganz einfach zerstören, wenn die Form des Kommentars nach links/rechts oder oben/unten gezogen wird.

    Jeder, der die Arbeitsmappe zusammen mit anderen benutzt, kann das Seitenverhältnis für die Hintergrundbilder beim Bearbeiten von Kommentaren ganz einfach zerstören. Wenn die Tabellen in der Arbeitsmappe eine große Anzahl von Kommentaren enthalten, ist es von Hand nicht mehr leistbar verzerrte Seitenverhältnisse zu korrigieren.

    Da ist guter Rat teuer.
    Bilder
    • comment.jpg

      192,12 kB, 736×471, 52 mal angesehen

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Zoe4711“ () aus folgendem Grund: Edit hinzugefügt

    Seitenverhältnis der Kommentare bewahren

    Diese Schnipsel gehören nicht in ein Modul, sondern unter Microsoft Exel Objekte in DieseArbeitsmappe.

    Diese Lösung funktioniert auch, wenn die Arbeitsmappe mehrere Tabellen enthält und auch dann, wenn zwischen Tabellen mehrfach hin- und hergewechselt wird.

    Diese Lösung setzt voraus, dass die Seitenverhälltnisse aller Kommentare in einer Tabelle identisch sind, z. Bsp.: Vereinslogo wurde als Hintergrundbild eingefügt.

    Diese Lösung bringt jedoch leider auch ein Problem mit sich, wenn die Tabelle Hunderte oder über Tausend Kommentare enthält, weil dann das Speichern der Datei für Benutzer*innen inakzeptabel lange dauert.

    Visual Basic-Quellcode

    1. Option Explicit
    2. Dim ScaleValue1(1 To 100) As Double
    3. Dim AktiveTabelle(1 To 100) As String
    4. Dim c As Integer
    5. Dim cmtc As Long
    6. Dim u As Integer
    7. Dim v As Integer
    8. Private Sub Workbook_BeforeClose(Cancel As Boolean)
    9. Dim objComment As Comment
    10. Dim ScaleValue2 As Double
    11. cmtc = 0
    12. u = 0
    13. v = 0
    14. For u = 1 To 100 '** bei wiederholtem sofortigen Wechsel zur selben Tabelle (mit nur einer anderen Tabelle dazwischen), _
    15. wird die Tabelle nur einmal berücksichtigt, die anderen Kommentar-Seitenverhältnisse derselben Tabelle werden zu Null gesetzt _
    16. und an Hand dessen übersprungen; so werden Mehrfach-Berechnungen vermieden.
    17. For v = (u + 2) To 100
    18. If AktiveTabelle(u) = AktiveTabelle(v) Then
    19. ScaleValue1(v) = 0
    20. End If
    21. Next v
    22. Next u
    23. For c = 1 To c
    24. If AktiveTabelle(c) = "" Then
    25. GoTo LabelSkip2
    26. ElseIf ScaleValue1(c) = 0 Then '** Tabellen deren Kommentar-Seitenverhältnis zu Null gesetzt wurde, werden übersprungen
    27. GoTo LabelSkip1
    28. End If
    29. Application.ScreenUpdating = False
    30. Application.Calculation = xlCalculationManual
    31. For Each objComment In Worksheets(AktiveTabelle(c)).Comments
    32. cmtc = cmtc + 1
    33. 'Resize
    34. With objComment.Shape
    35. .LockAspectRatio = msoFalse
    36. .TextFrame.AutoSize = False
    37. ScaleValue2 = .Height / .Width
    38. Debug.Print cmtc; c; ScaleValue1(c); ScaleValue2; AktiveTabelle(c)
    39. If ScaleValue2 <> ScaleValue1(c) Then
    40. .Width = 150
    41. .Height = .Width * ScaleValue1(c)
    42. .LockAspectRatio = msoTrue
    43. Debug.Print cmtc; c; ScaleValue1(c); ScaleValue2; .Width; .Height
    44. End If
    45. End With
    46. Debug.Print cmtc; c; ScaleValue1(c); ScaleValue2; objComment.Shape.Width; objComment.Shape.Height
    47. Next objComment
    48. LabelSkip1:
    49. Application.Calculation = xlCalculationAutomatic
    50. Application.ScreenUpdating = True
    51. DoEvents
    52. Next c
    53. LabelSkip2:
    54. Application.Calculation = xlCalculationAutomatic
    55. Application.ScreenUpdating = True
    56. For c = 1 To c
    57. Debug.Print c; ScaleValue1(c); AktiveTabelle(c)
    58. Next
    59. End Sub


    Visual Basic-Quellcode

    1. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    2. Dim objComment As Comment
    3. Dim ScaleValue2 As Double
    4. cmtc = 0
    5. u = 0
    6. v = 0
    7. For u = 1 To 100
    8. For v = (u + 2) To 100
    9. If AktiveTabelle(u) = AktiveTabelle(v) Then
    10. ScaleValue1(v) = 0
    11. End If
    12. Next v
    13. Next u
    14. For c = 1 To c
    15. If AktiveTabelle(c) = "" Then
    16. GoTo LabelSkip2
    17. ElseIf ScaleValue1(c) = 0 Then
    18. GoTo LabelSkip1
    19. End If
    20. Application.ScreenUpdating = False
    21. Application.Calculation = xlCalculationManual
    22. For Each objComment In Worksheets(AktiveTabelle(c)).Comments
    23. cmtc = cmtc + 1
    24. 'Resize
    25. With objComment.Shape
    26. .LockAspectRatio = msoFalse
    27. .TextFrame.AutoSize = False
    28. ScaleValue2 = .Height / .Width
    29. Debug.Print cmtc; c; ScaleValue1(c); ScaleValue2; AktiveTabelle(c)
    30. If ScaleValue2 <> ScaleValue1(c) Then
    31. .Width = 150
    32. .Height = .Width * ScaleValue1(c)
    33. .LockAspectRatio = msoTrue
    34. Debug.Print cmtc; c; ScaleValue1(c); ScaleValue2; .Width; .Height
    35. End If
    36. End With
    37. Debug.Print cmtc; c; ScaleValue1(c); ScaleValue2; objComment.Shape.Width; objComment.Shape.Height
    38. Next objComment
    39. LabelSkip1:
    40. Application.Calculation = xlCalculationAutomatic
    41. Application.ScreenUpdating = True
    42. DoEvents
    43. Next c
    44. LabelSkip2:
    45. Application.Calculation = xlCalculationAutomatic
    46. Application.ScreenUpdating = True
    47. For c = 1 To c
    48. Debug.Print c; ScaleValue1(c); AktiveTabelle(c)
    49. Next
    50. End Sub


    Visual Basic-Quellcode

    1. Private Sub Workbook_Open()
    2. Dim objComment As Comment
    3. Dim i As Integer
    4. Dim SV As Double
    5. i = 0
    6. c = 0
    7. c = c + 1
    8. For Each objComment In ActiveSheet.Comments
    9. i = i + 1
    10. With objComment.Shape
    11. SV = .Height / .Width
    12. End With
    13. If i = 1 Then GoTo LabelFinish
    14. Next
    15. LabelFinish:
    16. ScaleValue1(c) = SV
    17. AktiveTabelle(c) = ActiveSheet.Name
    18. Debug.Print c; SV; ScaleValue1(c); AktiveTabelle(c)
    19. End Sub


    Visual Basic-Quellcode

    1. Private Sub Workbook_SheetActivate(ByVal Sh As Object) '** Seitenverhältnis beim Tabellenwechsel wird ermittelt
    2. Dim objComment As Comment
    3. Dim i As Integer
    4. Dim SV As Double
    5. i = 0
    6. c = c + 1
    7. For Each objComment In ActiveSheet.Comments
    8. i = i + 1
    9. With objComment.Shape
    10. SV = .Height / .Width
    11. End With
    12. If i = 1 Then GoTo LabelFinish
    13. Next
    14. LabelFinish:
    15. ScaleValue1(c) = SV
    16. AktiveTabelle(c) = ActiveSheet.Name
    17. Debug.Print c; SV; ScaleValue1(c); AktiveTabelle(c)
    18. End Sub


    Ins Modul1 gehört zum Durcheinanderbringen aller Kommentare folgendes Schnipsel:

    Visual Basic-Quellcode

    1. Option Explicit
    2. Private Sub comments_mathematical_exact_arrangement()
    3. Dim objComment As Comment
    4. Dim i As Long
    5. Dim j As Double
    6. Dim z As Double
    7. i = 0
    8. If ActiveSheet.Comments.Count = 0 Then
    9. MsgBox "No comments in entire sheet"
    10. Exit Sub
    11. End If
    12. ' Alle Kommentare des aktuellen Arbeitsblatts durchlaufen
    13. Application.ScreenUpdating = False
    14. Application.Calculation = xlCalculationManual
    15. For Each objComment In ActiveSheet.Comments
    16. i = i + 1
    17. z = Rnd
    18. If z <= 0.1 Then
    19. j = i * z ^ 1
    20. ElseIf z <= 0.2 Then j = i * z ^ 2
    21. ElseIf z <= 0.3 Then j = i * z ^ 3
    22. ElseIf z <= 0.4 Then j = i * z ^ 4
    23. ElseIf z <= 0.5 Then j = i * z ^ 5
    24. ElseIf z <= 0.6 Then j = i * z ^ 6
    25. ElseIf z <= 0.7 Then j = i * z ^ 7
    26. ElseIf z <= 0.8 Then j = i * z ^ 8
    27. ElseIf z <= 0.9 Then j = i * z ^ 9
    28. ElseIf z <= 1 Then j = i * z ^ 10
    29. End If
    30. With objComment
    31. .Shape.TextFrame.AutoSize = True
    32. If j <= 10 Then
    33. .Shape.Top = .Parent.Top + (.Parent.Height * (j / 10))
    34. .Shape.Left = .Parent.Left + (.Parent.Width * (j / 10))
    35. ElseIf j <= 100 Then
    36. .Shape.Top = .Parent.Top + (.Parent.Height * (j / 10))
    37. .Shape.Left = .Parent.Left + (.Parent.Width * (j / 100))
    38. ElseIf j <= 1000 Then
    39. .Shape.Top = .Parent.Top + (.Parent.Height * (j / 10))
    40. .Shape.Left = .Parent.Left + (.Parent.Width * (j / 1000))
    41. ElseIf j <= 10000 Then
    42. .Shape.Top = .Parent.Top + (.Parent.Height * (j / 100))
    43. .Shape.Left = .Parent.Left + (.Parent.Width * (j / 100))
    44. End If
    45. End With
    46. Next
    47. Application.Calculation = xlCalculationAutomatic
    48. Application.ScreenUpdating = True
    49. On Error GoTo 0
    50. End Sub


    comment size change revert back picture (1).xlsx als comment size change revert back picture (1).xlsm speichern, Schnipsel einfügen und ausprobieren.
    Dateien

    Arbeitsmappe mit max. 5 Tabellen, Kommentare mit unterschiedlichen Seitenverhältnissen, Seitenverhältnis der Kommentare bewahren

    Diese Schnipsel gehören nicht in ein Modul, sondern unter Microsoft Exel Objekte in DieseArbeitsmappe.

    Diese Lösung funktioniert auch, wenn die Arbeitsmappe bis zu max. 5 Tabellen enthält und auch dann, wenn zwischen Tabellen mehrfach hin- und hergewechselt wird.

    Diese Lösung funktioniert auch, wenn die Seitenverhälltnisse aller Kommentare in einer Tabelle unterschiedlich sind., z. Bsp.: wenn in jedem Kommentar ein anderes Hintergrundbild eingefügt wird.

    Diese Lösung bringt jedoch leider auch ein Problem mit sich, wenn die Tabelle Hunderte oder über Tausend Kommentare enthält, weil dann das Speichern der Datei für Benutzer*innen gefühlt "inakzeptabel lange" dauert.

    Visual Basic-Quellcode

    1. Option Explicit
    2. Option Base 1
    3. Private ws As Worksheet
    4. Dim cmtamount(5) As Integer
    5. Dim SV1() As Double
    6. Dim SV2() As Double
    7. Dim SV3() As Double
    8. Dim SV4() As Double
    9. Dim SV5() As Double
    10. Dim AktiveTabelle(1 To 100) As String
    11. Dim AktiveTabelle2(1 To 1) As String
    12. Dim c1 As Integer
    13. Dim c2 As Integer
    14. Dim c3 As Integer
    15. Dim c4 As Integer
    16. Dim c5 As Integer
    17. Dim cmtc As Long
    18. Dim i As Integer
    19. Dim j As Integer
    20. Private Sub Workbook_BeforeClose(Cancel As Boolean)
    21. Dim objComment As Comment
    22. Dim ScaleValue2 As Double
    23. c3 = c1
    24. cmtc = 0
    25. If ActiveSheet.Comments.Count = 0 Then
    26. MsgBox "No comments in entire sheet"
    27. End If
    28. Application.ScreenUpdating = False
    29. Application.Calculation = xlCalculationManual
    30. For c1 = 1 To c3
    31. cmtc = 0
    32. Application.ScreenUpdating = False
    33. Application.Calculation = xlCalculationManual
    34. Select Case c1
    35. Case 1
    36. For Each objComment In Worksheets(AktiveTabelle(c1)).Comments
    37. cmtc = cmtc + 1
    38. 'Resize
    39. With objComment.Shape
    40. .LockAspectRatio = msoFalse
    41. .TextFrame.AutoSize = False
    42. ScaleValue2 = .Height / .Width
    43. Debug.Print cmtc; c1; SV1(cmtc); ScaleValue2; AktiveTabelle(c1)
    44. If ScaleValue2 <> SV1(cmtc) Then
    45. .Width = 150
    46. .Height = .Width * SV1(cmtc)
    47. .LockAspectRatio = msoTrue
    48. Debug.Print cmtc; c1; SV1(cmtc); ScaleValue2; .Width; .Height
    49. End If
    50. End With
    51. Debug.Print cmtc; c1; SV1(cmtc); ScaleValue2; objComment.Shape.Width; objComment.Shape.Height
    52. Next objComment
    53. Case 2
    54. For Each objComment In Worksheets(AktiveTabelle(c1)).Comments
    55. cmtc = cmtc + 1
    56. 'Resize
    57. With objComment.Shape
    58. .LockAspectRatio = msoFalse
    59. .TextFrame.AutoSize = False
    60. ScaleValue2 = .Height / .Width
    61. Debug.Print cmtc; c1; SV2(cmtc); ScaleValue2; AktiveTabelle(c1)
    62. If ScaleValue2 <> SV2(cmtc) Then
    63. .Width = 150
    64. .Height = .Width * SV2(cmtc)
    65. .LockAspectRatio = msoTrue
    66. Debug.Print cmtc; c1; SV2(cmtc); ScaleValue2; .Width; .Height
    67. End If
    68. End With
    69. Debug.Print cmtc; c1; SV2(cmtc); ScaleValue2; objComment.Shape.Width; objComment.Shape.Height
    70. Next objComment
    71. Case 3
    72. For Each objComment In Worksheets(AktiveTabelle(c1)).Comments
    73. cmtc = cmtc + 1
    74. 'Resize
    75. With objComment.Shape
    76. .LockAspectRatio = msoFalse
    77. .TextFrame.AutoSize = False
    78. ScaleValue2 = .Height / .Width
    79. Debug.Print cmtc; c1; SV3(cmtc); ScaleValue2; AktiveTabelle(c1)
    80. If ScaleValue2 <> SV3(cmtc) Then
    81. .Width = 150
    82. .Height = .Width * SV3(cmtc)
    83. .LockAspectRatio = msoTrue
    84. Debug.Print cmtc; c1; SV3(cmtc); ScaleValue2; .Width; .Height
    85. End If
    86. End With
    87. Debug.Print cmtc; c1; SV3(cmtc); ScaleValue2; objComment.Shape.Width; objComment.Shape.Height
    88. Next objComment
    89. Case 4
    90. For Each objComment In Worksheets(AktiveTabelle(c1)).Comments
    91. cmtc = cmtc + 1
    92. 'Resize
    93. With objComment.Shape
    94. .LockAspectRatio = msoFalse
    95. .TextFrame.AutoSize = False
    96. ScaleValue2 = .Height / .Width
    97. Debug.Print cmtc; c1; SV4(cmtc); ScaleValue2; AktiveTabelle(c1)
    98. If ScaleValue2 <> SV4(cmtc) Then
    99. .Width = 150
    100. .Height = .Width * SV4(cmtc)
    101. .LockAspectRatio = msoTrue
    102. Debug.Print cmtc; c1; SV4(cmtc); ScaleValue2; .Width; .Height
    103. End If
    104. End With
    105. Debug.Print cmtc; c1; SV4(cmtc); ScaleValue2; objComment.Shape.Width; objComment.Shape.Height
    106. Next objComment
    107. Case 5
    108. For Each objComment In Worksheets(AktiveTabelle(c1)).Comments
    109. cmtc = cmtc + 1
    110. 'Resize
    111. With objComment.Shape
    112. .LockAspectRatio = msoFalse
    113. .TextFrame.AutoSize = False
    114. ScaleValue2 = .Height / .Width
    115. Debug.Print cmtc; c1; SV5(cmtc); ScaleValue2; AktiveTabelle(c1)
    116. If ScaleValue2 <> SV5(cmtc) Then
    117. .Width = 150
    118. .Height = .Width * SV5(cmtc)
    119. .LockAspectRatio = msoTrue
    120. Debug.Print cmtc; c1; SV5(cmtc); ScaleValue2; .Width; .Height
    121. End If
    122. End With
    123. Debug.Print cmtc; c1; SV5(cmtc); ScaleValue2; objComment.Shape.Width; objComment.Shape.Height
    124. Next objComment
    125. Case Else
    126. End Select
    127. DoEvents
    128. Next c1
    129. Application.Calculation = xlCalculationAutomatic
    130. Application.ScreenUpdating = True
    131. For c1 = 1 To c3
    132. Select Case c1
    133. Case 1
    134. For j = 1 To cmtamount(c1)
    135. Debug.Print j; SV1(j); c1; AktiveTabelle(c1); cmtamount(c1); ActiveSheet.Comments.Count; ActiveSheet.Name
    136. Next
    137. Case 2
    138. For j = 1 To cmtamount(c1)
    139. Debug.Print j; SV2(j); c1; AktiveTabelle(c1); cmtamount(c1); ActiveSheet.Comments.Count; ActiveSheet.Name
    140. Next
    141. Case 3
    142. For j = 1 To cmtamount(c1)
    143. Debug.Print j; SV3(j); c1; AktiveTabelle(c1); cmtamount(c1); ActiveSheet.Comments.Count; ActiveSheet.Name
    144. Next
    145. Case 4
    146. For j = 1 To cmtamount(c1)
    147. Debug.Print j; SV4(j); c1; AktiveTabelle(c1); cmtamount(c1); ActiveSheet.Comments.Count; ActiveSheet.Name
    148. Next
    149. Case 5
    150. For j = 1 To cmtamount(c1)
    151. Debug.Print j; SV5(j); c1; AktiveTabelle(c1); cmtamount(c1); ActiveSheet.Comments.Count; ActiveSheet.Name
    152. Next
    153. Case Else
    154. End Select
    155. Next
    156. c1 = c1 - 1
    157. End Sub


    Visual Basic-Quellcode

    1. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    2. Dim objComment As Comment
    3. Dim ScaleValue2 As Double
    4. c4 = c2
    5. cmtc = 0
    6. If ActiveSheet.Comments.Count = 0 Then
    7. MsgBox "No comments in entire sheet"
    8. End If
    9. For c2 = 1 To c4
    10. cmtc = 0
    11. Application.ScreenUpdating = False
    12. Application.Calculation = xlCalculationManual
    13. Select Case c2
    14. Case 1
    15. For Each objComment In Worksheets(AktiveTabelle(c2)).Comments
    16. cmtc = cmtc + 1
    17. 'Resize
    18. With objComment.Shape
    19. .LockAspectRatio = msoFalse
    20. .TextFrame.AutoSize = False
    21. ScaleValue2 = .Height / .Width
    22. Debug.Print cmtc; c2; SV1(cmtc); ScaleValue2; AktiveTabelle(c2)
    23. If ScaleValue2 <> SV1(cmtc) Then
    24. .Width = 150
    25. .Height = .Width * SV1(cmtc)
    26. .LockAspectRatio = msoTrue
    27. Debug.Print cmtc; c2; SV1(cmtc); ScaleValue2; .Width; .Height
    28. End If
    29. End With
    30. Debug.Print cmtc; c2; SV1(cmtc); ScaleValue2; objComment.Shape.Width; objComment.Shape.Height
    31. Next objComment
    32. Case 2
    33. For Each objComment In Worksheets(AktiveTabelle(c2)).Comments
    34. cmtc = cmtc + 1
    35. 'Resize
    36. With objComment.Shape
    37. .LockAspectRatio = msoFalse
    38. .TextFrame.AutoSize = False
    39. ScaleValue2 = .Height / .Width
    40. Debug.Print cmtc; c2; SV2(cmtc); ScaleValue2; AktiveTabelle(c2)
    41. If ScaleValue2 <> SV2(cmtc) Then
    42. .Width = 150
    43. .Height = .Width * SV2(cmtc)
    44. .LockAspectRatio = msoTrue
    45. Debug.Print cmtc; c2; SV2(cmtc); ScaleValue2; .Width; .Height
    46. End If
    47. End With
    48. Debug.Print cmtc; c2; SV2(cmtc); ScaleValue2; objComment.Shape.Width; objComment.Shape.Height
    49. Next objComment
    50. Case 3
    51. For Each objComment In Worksheets(AktiveTabelle(c2)).Comments
    52. cmtc = cmtc + 1
    53. 'Resize
    54. With objComment.Shape
    55. .LockAspectRatio = msoFalse
    56. .TextFrame.AutoSize = False
    57. ScaleValue2 = .Height / .Width
    58. Debug.Print cmtc; c2; SV3(cmtc); ScaleValue2; AktiveTabelle(c2)
    59. If ScaleValue2 <> SV3(cmtc) Then
    60. .Width = 150
    61. .Height = .Width * SV3(cmtc)
    62. .LockAspectRatio = msoTrue
    63. Debug.Print cmtc; c2; SV3(cmtc); ScaleValue2; .Width; .Height
    64. End If
    65. End With
    66. Debug.Print cmtc; c2; SV3(cmtc); ScaleValue2; objComment.Shape.Width; objComment.Shape.Height
    67. Next objComment
    68. Case 4
    69. For Each objComment In Worksheets(AktiveTabelle(c2)).Comments
    70. cmtc = cmtc + 1
    71. 'Resize
    72. With objComment.Shape
    73. .LockAspectRatio = msoFalse
    74. .TextFrame.AutoSize = False
    75. ScaleValue2 = .Height / .Width
    76. Debug.Print cmtc; c2; SV4(cmtc); ScaleValue2; AktiveTabelle(c2)
    77. If ScaleValue2 <> SV4(cmtc) Then
    78. .Width = 150
    79. .Height = .Width * SV4(cmtc)
    80. .LockAspectRatio = msoTrue
    81. Debug.Print cmtc; c2; SV4(cmtc); ScaleValue2; .Width; .Height
    82. End If
    83. End With
    84. Debug.Print cmtc; c2; SV4(cmtc); ScaleValue2; objComment.Shape.Width; objComment.Shape.Height
    85. Next objComment
    86. Case 5
    87. For Each objComment In Worksheets(AktiveTabelle(c2)).Comments
    88. cmtc = cmtc + 1
    89. 'Resize
    90. With objComment.Shape
    91. .LockAspectRatio = msoFalse
    92. .TextFrame.AutoSize = False
    93. ScaleValue2 = .Height / .Width
    94. Debug.Print cmtc; c2; SV5(cmtc); ScaleValue2; AktiveTabelle(c2)
    95. If ScaleValue2 <> SV5(cmtc) Then
    96. .Width = 150
    97. .Height = .Width * SV5(cmtc)
    98. .LockAspectRatio = msoTrue
    99. Debug.Print cmtc; c2; SV5(cmtc); ScaleValue2; .Width; .Height
    100. End If
    101. End With
    102. Debug.Print cmtc; c2; SV5(cmtc); ScaleValue2; objComment.Shape.Width; objComment.Shape.Height
    103. Next objComment
    104. Case Else
    105. End Select
    106. DoEvents
    107. Next c2
    108. Application.Calculation = xlCalculationAutomatic
    109. Application.ScreenUpdating = True
    110. For c2 = 1 To c4
    111. Select Case c2
    112. Case 1
    113. For j = 1 To cmtamount(c2)
    114. Debug.Print j; SV1(j); c2; AktiveTabelle(c2); cmtamount(c2); ActiveSheet.Comments.Count; ActiveSheet.Name
    115. Next
    116. Case 2
    117. For j = 1 To cmtamount(c2)
    118. Debug.Print j; SV2(j); c2; AktiveTabelle(c2); cmtamount(c2); ActiveSheet.Comments.Count; ActiveSheet.Name
    119. Next
    120. Case 3
    121. For j = 1 To cmtamount(c2)
    122. Debug.Print j; SV3(j); c2; AktiveTabelle(c2); cmtamount(c2); ActiveSheet.Comments.Count; ActiveSheet.Name
    123. Next
    124. Case 4
    125. For j = 1 To cmtamount(c2)
    126. Debug.Print j; SV4(j); c2; AktiveTabelle(c2); cmtamount(c2); ActiveSheet.Comments.Count; ActiveSheet.Name
    127. Next
    128. Case 5
    129. For j = 1 To cmtamount(c2)
    130. Debug.Print j; SV5(j); c2; AktiveTabelle(c2); cmtamount(c2); ActiveSheet.Comments.Count; ActiveSheet.Name
    131. Next
    132. Case Else
    133. End Select
    134. Next
    135. c2 = c2 - 1
    136. End Sub


    Visual Basic-Quellcode

    1. Private Sub Workbook_Open()
    2. Dim objComment As Comment
    3. If ActiveSheet.Comments.Count = 0 Then
    4. MsgBox "No comments in entire sheet"
    5. Exit Sub
    6. End If
    7. i = 0
    8. c1 = 0
    9. c1 = c1 + 1
    10. c2 = 0
    11. c2 = c2 + 1
    12. ReDim Preserve SV1(1 To ActiveSheet.Comments.Count)
    13. cmtamount(1) = ActiveSheet.Comments.Count
    14. AktiveTabelle(c1) = ActiveSheet.Name
    15. AktiveTabelle(c2) = ActiveSheet.Name
    16. For Each objComment In ActiveSheet.Comments
    17. i = i + 1
    18. With objComment.Shape
    19. SV1(i) = .Height / .Width
    20. End With
    21. Debug.Print i; SV1(i); c1; AktiveTabelle(c1); cmtamount(c1); ActiveSheet.Comments.Count; ActiveSheet.Name
    22. Next
    23. End Sub


    Visual Basic-Quellcode

    1. Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    2. Dim objComment As Comment
    3. If ActiveSheet.Comments.Count = 0 Then
    4. c5 = 1
    5. AktiveTabelle2(c5) = ActiveSheet.Name
    6. Debug.Print AktiveTabelle2(c5)
    7. MsgBox "No comments in entire sheet"
    8. Exit Sub
    9. End If
    10. i = 0
    11. c1 = c1 + 1
    12. c2 = c2 + 1
    13. AktiveTabelle(c1) = ActiveSheet.Name
    14. AktiveTabelle(c2) = ActiveSheet.Name
    15. If c5 = 1 Then
    16. If c1 = 2 Then
    17. If AktiveTabelle(c1) = AktiveTabelle(c1 - 1) Then
    18. c5 = 0
    19. c1 = c1 - 1
    20. c2 = c2 - 1
    21. Exit Sub
    22. End If
    23. End If
    24. If c1 = 3 Then
    25. If AktiveTabelle(c1) = AktiveTabelle(c1 - 1) Then
    26. c5 = 0
    27. c1 = c1 - 1
    28. c2 = c2 - 1
    29. Exit Sub
    30. End If
    31. End If
    32. If c1 = 4 Then
    33. If AktiveTabelle(c1) = AktiveTabelle(c1 - 1) Then
    34. c5 = 0
    35. c1 = c1 - 1
    36. c2 = c2 - 1
    37. Exit Sub
    38. End If
    39. End If
    40. If c1 = 5 Then
    41. If AktiveTabelle(c1) = AktiveTabelle(c1 - 1) Then
    42. c5 = 0
    43. c1 = c1 - 1
    44. c2 = c2 - 1
    45. Exit Sub
    46. End If
    47. End If
    48. End If
    49. If c1 > 2 Then
    50. 'On Error Resume Next
    51. If AktiveTabelle(c1) = AktiveTabelle(c1 - 1) Then
    52. c1 = c1 - 1
    53. c2 = c2 - 1
    54. GoTo LabelEnd
    55. ElseIf AktiveTabelle(c1) = AktiveTabelle(c1 - 2) Then
    56. c1 = c1 - 1
    57. c2 = c2 - 1
    58. GoTo LabelEnd
    59. End If
    60. End If
    61. If c1 > 3 Then
    62. If AktiveTabelle(c1) = AktiveTabelle(c1 - 3) Then
    63. c1 = c1 - 1
    64. c2 = c2 - 1
    65. GoTo LabelEnd
    66. End If
    67. End If
    68. If c1 > 4 Then
    69. If AktiveTabelle(c1) = AktiveTabelle(c1 - 4) Then
    70. c1 = c1 - 1
    71. c2 = c2 - 1
    72. GoTo LabelEnd
    73. End If
    74. End If
    75. If c1 = 5 Then
    76. If AktiveTabelle(c1) = AktiveTabelle(c1 - 4) Then
    77. c1 = c1 - 1
    78. c2 = c2 - 1
    79. GoTo LabelEnd
    80. End If
    81. End If
    82. On Error GoTo 0
    83. If c1 = 1 Then
    84. ReDim Preserve SV1(1 To ActiveSheet.Comments.Count)
    85. cmtamount(1) = ActiveSheet.Comments.Count
    86. For Each objComment In ActiveSheet.Comments
    87. i = i + 1
    88. With objComment.Shape
    89. SV1(i) = .Height / .Width
    90. End With
    91. Debug.Print i; SV1(i); c1; AktiveTabelle(c1); cmtamount(c1); ActiveSheet.Comments.Count; ActiveSheet.Name
    92. Next
    93. ElseIf c1 = 2 Then
    94. ReDim Preserve SV2(1 To ActiveSheet.Comments.Count)
    95. cmtamount(2) = ActiveSheet.Comments.Count
    96. For Each objComment In ActiveSheet.Comments
    97. i = i + 1
    98. With objComment.Shape
    99. SV2(i) = .Height / .Width
    100. End With
    101. Debug.Print i; SV2(i); c1; AktiveTabelle(c1); cmtamount(c1); ActiveSheet.Comments.Count; ActiveSheet.Name
    102. Next
    103. ElseIf c1 = 3 Then
    104. ReDim Preserve SV3(1 To ActiveSheet.Comments.Count)
    105. cmtamount(3) = ActiveSheet.Comments.Count
    106. AktiveTabelle(c1) = ActiveSheet.Name
    107. AktiveTabelle(c2) = ActiveSheet.Name
    108. For Each objComment In ActiveSheet.Comments
    109. i = i + 1
    110. With objComment.Shape
    111. SV3(i) = .Height / .Width
    112. End With
    113. Debug.Print i; SV3(i); c1; AktiveTabelle(c1); cmtamount(c1); ActiveSheet.Comments.Count; ActiveSheet.Name
    114. Next
    115. ElseIf c1 = 4 Then
    116. ReDim Preserve SV4(1 To ActiveSheet.Comments.Count)
    117. cmtamount(4) = ActiveSheet.Comments.Count
    118. AktiveTabelle(c1) = ActiveSheet.Name
    119. AktiveTabelle(c2) = ActiveSheet.Name
    120. For Each objComment In ActiveSheet.Comments
    121. i = i + 1
    122. With objComment.Shape
    123. SV4(i) = .Height / .Width
    124. End With
    125. Debug.Print i; SV4(i); c1; AktiveTabelle(c1); cmtamount(c1); ActiveSheet.Comments.Count; ActiveSheet.Name
    126. Next
    127. ElseIf c1 = 5 Then
    128. ReDim Preserve SV5(1 To ActiveSheet.Comments.Count)
    129. cmtamount(5) = ActiveSheet.Comments.Count
    130. AktiveTabelle(c1) = ActiveSheet.Name
    131. AktiveTabelle(c2) = ActiveSheet.Name
    132. For Each objComment In ActiveSheet.Comments
    133. i = i + 1
    134. With objComment.Shape
    135. SV5(i) = .Height / .Width
    136. End With
    137. Debug.Print i; SV5(i); c1; AktiveTabelle(c1); cmtamount(c1); ActiveSheet.Comments.Count; ActiveSheet.Name
    138. Next
    139. LabelEnd:
    140. On Error GoTo 0
    141. End If
    142. End Sub


    Ins Modul1 gehört zum Durcheinanderbringen aller Kommentare folgendes Schnipsel:

    Visual Basic-Quellcode

    1. Option Explicit
    2. Private Sub comments_mathematical_exact_arrangement()
    3. Dim objComment As Comment
    4. Dim i As Long
    5. Dim j As Double
    6. Dim z As Double
    7. i = 0
    8. If ActiveSheet.Comments.Count = 0 Then
    9. MsgBox "No comments in entire sheet"
    10. Exit Sub
    11. End If
    12. ' Alle Kommentare des aktuellen Arbeitsblatts durchlaufen
    13. Application.ScreenUpdating = False
    14. Application.Calculation = xlCalculationManual
    15. For Each objComment In ActiveSheet.Comments
    16. i = i + 1
    17. z = Rnd
    18. If z <= 0.1 Then
    19. j = i * z ^ 1
    20. ElseIf z <= 0.2 Then j = i * z ^ 2
    21. ElseIf z <= 0.3 Then j = i * z ^ 3
    22. ElseIf z <= 0.4 Then j = i * z ^ 4
    23. ElseIf z <= 0.5 Then j = i * z ^ 5
    24. ElseIf z <= 0.6 Then j = i * z ^ 6
    25. ElseIf z <= 0.7 Then j = i * z ^ 7
    26. ElseIf z <= 0.8 Then j = i * z ^ 8
    27. ElseIf z <= 0.9 Then j = i * z ^ 9
    28. ElseIf z <= 1 Then j = i * z ^ 10
    29. End If
    30. With objComment
    31. .Shape.TextFrame.AutoSize = True
    32. If j <= 10 Then
    33. .Shape.Top = .Parent.Top + (.Parent.Height * (j / 10))
    34. .Shape.Left = .Parent.Left + (.Parent.Width * (j / 10))
    35. ElseIf j <= 100 Then
    36. .Shape.Top = .Parent.Top + (.Parent.Height * (j / 10))
    37. .Shape.Left = .Parent.Left + (.Parent.Width * (j / 100))
    38. ElseIf j <= 1000 Then
    39. .Shape.Top = .Parent.Top + (.Parent.Height * (j / 10))
    40. .Shape.Left = .Parent.Left + (.Parent.Width * (j / 1000))
    41. ElseIf j <= 10000 Then
    42. .Shape.Top = .Parent.Top + (.Parent.Height * (j / 100))
    43. .Shape.Left = .Parent.Left + (.Parent.Width * (j / 100))
    44. End If
    45. End With
    46. Next
    47. Application.Calculation = xlCalculationAutomatic
    48. Application.ScreenUpdating = True
    49. On Error GoTo 0
    50. End Sub


    comments with pictures (max 5 Tabellen).xlsx als comments with pictures (max 5 Tabellen).xlsm speichern, Schnipsel einfügen und ausprobieren.
    Dateien

    Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von „Zoe4711“ () aus folgendem Grund: Fehlerkorrektur; redaktionelle Änderung