Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1376to1380
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

Bild in Kommentar per VBA

Bild in Kommentar per VBA
02.09.2014 12:25:52
Chris
Hallo VBAler
ich bastele gerade an einem Makro, dass mir in einem bestimmten range für jede Zelle ein Kommentar in Form eines Bildes einfügt. Dabei soll jede Zelle ein anderes Bild im Kommentar enthalten.
Ich erhalte die Fehlermeldung "Nicht genügend Speicher", obwohl die Bilder nur wenige KB groß sind. Pfad ist fest, Bildname variable und steht in Zelle a der Spalte A.
Zusätzlich benötige ich noch: Wenn die entsprechende Bilddatei nicht vorhanden ist, soll der entsprechende Fehler abgefangen werden bzw. das Kommentarfeld einfach leer sein.
Schon mal danke,Chris
Dim a As Integer, cmt As Comment
With Sheets(1)
For a = 12 To 13
pfad = "C:\Users\Mustermann\Desktop\" & .Cells(a, 1).Value & ".png"
With .Cells(a, 2)
.ClearComments
.AddComment
.Comment.Visible = False
.Comment.Shape.DrawingObject.AutoSize = True
.Comment.Shape.TextFrame.Characters.Font.Bold = True
.Comment.Shape.TextFrame.Characters.Font.Size = 12
.Comment.Shape.Fill.UserPicture pfad
.Comment.Shape.Width = 450
.Comment.Shape.Height = 550
End With
Next
End With
End Sub

4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Bild in Kommentar per VBA
02.09.2014 17:24:09
fcs
Hallo Chris,
die Prüfung, ob das jeweilige Bild vorhanden ist ist kein Problem.
In deinem geposteten Makro fügst du ja nur 2 Kommentare mit Bild ein.
Wenn du aber wesentlich mehr Bilder in Kommentare einfügts gibt es eine Grenze für die Anzahl der Kommentare oder auch Shapes oder irgendwelche andere Grenzen innerhalb von Excel, die ich aber nicht kenne.
Wenn viele verschieden Bilder in die Kommentare lädst, dann schlägt das auf die Dateigröße durch.
Gruß
Franz
Sub MakeCommentWithPicture()
Dim a As Integer, cmt As Comment, Pfad
With Sheets(1)
For a = 12 To 35
Pfad = "C:\Users\Mustermann\Desktop\" & .Cells(a, 1).Value & ".png"
Pfad = "D:\Test\Bilder\" & .Cells(a, 1).Value & ".png"
With .Cells(a, 2)
.ClearComments
.AddComment
.Comment.Visible = False
If Dir(Pfad)  "" Then
.Comment.Shape.DrawingObject.AutoSize = True
With .Comment.Shape.TextFrame.Characters
.Font.Bold = True
.Font.Size = 12
End With
.Comment.Shape.Fill.UserPicture Pfad
.Comment.Shape.Width = 450
.Comment.Shape.Height = 550
Else
With .Comment.Shape.TextFrame.Characters
.Font.Bold = True
.Font.Size = 12
.Text = "kein Bild"
End With
End If
End With
Next
End With
End Sub

Anzeige
AW: Bild in Kommentar per VBA
03.09.2014 07:36:44
Chris
Hallo Franz,
danke für dein Makro - läuft.
Was bedeuten die Zeilen:
If Dir(Pfad) "" Then
.Comment.Shape.DrawingObject.AutoSize = True
With .Comment.Shape.TextFrame.Characters
.Font.Bold = True
.Font.Size = 12
End With
So viel wie: Wenn du im Pfad XY irgendetwas findest? ("" = irgendwas ?) dann
formatiere das Kommentar wie angegeben autosize etc..
Könnte man das nicht auch weglassen:
if Dir(Pfad) "" Then
.Comment.Shape.Fill.UserPicture Pfad
.Comment.Shape.Width = 450
.Comment.Shape.Height = 550
Else
With .Comment.Shape.TextFrame.Characters
.Font.Bold = True
.Font.Size = 12
.Text = "kein Bild"
End With
End If
End With
funktioniert auch bei mir...

Anzeige
AW: Bild in Kommentar per VBA
03.09.2014 09:52:01
fcs
Hallo Chris,
natürlich kannst du Formatierungen weglassen. Dann haben die Kommentare mit Bild für Texte die Standardformatierung.
Die Text-Formatierung ist ja nicht von mir erfunden, sie war in deinem ursprünglichen Makro schon drin.
Gruß
Franz

AW: Bild in Kommentar per VBA
03.09.2014 08:49:02
Chris
Hallo Franz,
danke für dein Makro - läuft.
Was bedeuten die Zeilen:
If Dir(Pfad) "" Then
.Comment.Shape.DrawingObject.AutoSize = True
With .Comment.Shape.TextFrame.Characters
.Font.Bold = True
.Font.Size = 12
End With
So viel wie: Wenn du im Pfad XY irgendetwas findest? ("" = irgendwas ?) dann
formatiere das Kommentar wie angegeben autosize etc..
Könnte man das nicht auch weglassen:
if Dir(Pfad) "" Then
.Comment.Shape.Fill.UserPicture Pfad
.Comment.Shape.Width = 450
.Comment.Shape.Height = 550
Else
With .Comment.Shape.TextFrame.Characters
.Font.Bold = True
.Font.Size = 12
.Text = "kein Bild"
End With
End If
End With
funktioniert auch bei mir...
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige