Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1316to1320
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 aktive Zelle einfügen

Bild in aktive Zelle einfügen
18.06.2013 15:41:23
Albert
Hallo zusammen,
ich verwende folgenden Code, um ein Bild entweder im Hochformat bzw. im Querformat einzufügen.
Was allerdings nicht funktioniert ist die Position.
Vielleicht wisst ihr eine Lösung?
Option Explicit
Dim Bild As Variant
Private Sub Ok_Click()
Dim Location As Integer
Location = ActiveCell.Select
Bild = Application.GetOpenFilename("C:\,*.jpg")
If Bild  0 Then
On Error GoTo fehlerbehandlung
ActiveSheet.Pictures.Insert (Bild)
'On Error GoTo 0
If FileLen(Bild) / 1024 > 500 Then
MsgBox ("Die Bilddateigröße übersteigt die 200kb Größe! Bitte reduzieren sie erst die  _
Dateigröße!")
Exit Sub
Else
If querformat.Value = True Then
If TypeName(Selection) = "Picture" Or TypeName(Selection) = "Grafik" Then 'nur  _
wenn Grafik markiert ist :
With Selection.ShapeRange(Location)
.LockAspectRatio = True
'Breite und Höhe der Grafik bitte in Klammer hier anpassen :
'.Height = Application.CentimetersToPoints(6.77)
.Top = Selection.Top
.Left = Selection.Left
.Width = Application.CentimetersToPoints(9)
End With
End If
End If
If hochformat.Value = True Then
If TypeName(Selection) = "Picture" Or TypeName(Selection) = "Grafik" Then 'nur  _
wenn Grafik markiert ist :
With Selection.ShapeRange
.LockAspectRatio = True
'Breite und Höhe der Grafik bitte in Klammer hier anpassen :
'.Height = Application.CentimetersToPoints(9)
.Top = Selection.Top
.Left = Selection.Left
.Width = Application.CentimetersToPoints(7.25)
End With
End If
End If
End If
End If
Exit Sub
fehlerbehandlung:
If Err.Number = 1004 Then MsgBox "Fehler beim Einfügen der Grafik!" _
& Chr(13) & Chr(13) & "Wahrscheinlich kein lesbares Grafikformat"
End Sub
Dank und Gruß
A.

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

Betreff
Datum
Anwender
Anzeige
AW: Bild in aktive Zelle einfügen
18.06.2013 16:02:07
Rudi
Hallo,
1. würde ich Location nicht als Variablennamen benutzen, da es eine Eigenschaft diverser Objekte ist.
2. Dim Location As Integer
wenn dann Dim Location as Range
3. was ist das für ein Konstrukt?: Location = ActiveCell.Select
wenn, dann Set Location=ActiveCell
4. .Top = Selection.Top
Selection ist doch jetzt das Bild.
Ergo: .Top = Location.Top
5. solltest du dir angewöhnen, alle Variablen zu deklarieren.
Grob überarbeitet:
Sub Ok_Click()
Dim rngLocation As Range
Set rngLocation = ActiveCell
Bild = Application.GetOpenFilename("C:\,*.jpg")
If Bild  0 Then
On Error GoTo fehlerbehandlung
ActiveSheet.Pictures.Insert(Bild).Select
'On Error GoTo 0
If FileLen(Bild) / 1024 > 500 Then
MsgBox ("Die Bilddateigröße übersteigt die 200kb Größe! Bitte reduzieren sie erst die  _
Dateigröße! ")
Exit Sub
Else
If querformat = True Then
If TypeName(Selection) = "Picture" Or TypeName(Selection) = "Grafik" Then 'nur  _
_
wenn Grafik markiert ist :
With Selection.ShapeRange
.LockAspectRatio = True
'Breite und Höhe der Grafik bitte in Klammer hier anpassen :
'.Height = Application.CentimetersToPoints(6.77)
.Top = rngLocation.Top
.Left = rngLocation.Left
.Width = Application.CentimetersToPoints(9)
End With
End If
End If
If hochformat = True Then
If TypeName(Selection) = "Picture" Or TypeName(Selection) = "Grafik" Then 'nur  _
_
wenn Grafik markiert ist :
With Selection.ShapeRange
.LockAspectRatio = True
'Breite und Höhe der Grafik bitte in Klammer hier anpassen :
'.Height = Application.CentimetersToPoints(9)
.Top = rngLocation.Top
.Left = rngLocation.Left
.Width = Application.CentimetersToPoints(7.25)
End With
End If
End If
End If
End If
Exit Sub
fehlerbehandlung:
If Err.Number = 1004 Then MsgBox "Fehler beim Einfügen der Grafik!" _
& Chr(13) & Chr(13) & "Wahrscheinlich kein lesbares Grafikformat"
End Sub
Gruß
Rudi

Anzeige
AW => Rudi: Bild in aktive Zelle einfügen
19.06.2013 08:11:14
Albert
Moin Rudi,
danke für deine Hinweise. Es war mir nicht bewusst, dass Location zusätzliche Verwendung hat. Es kam auch keine Fehlermeldung o.ä.
Die Abbruchbedingung muss ich nochmal durchgehen. Denn wenn eine Datei größer ist als 200kb kommt zwar die Msgbox mit dem Hinweis, ignoriert aber den Hinweis und fügt das Bild dennoch ein.
Des Weiteren möchte ich noch gucken, ob is statt der .Left = Selection.Left auch ein .Center gibt.
Danke für deine Hilfe.
Gruß
A.

AW: AW => Rudi: Bild in aktive Zelle einfügen
19.06.2013 14:06:38
Rudi
Hallo,
Die Abbruchbedingung muss ich nochmal durchgehen. Denn wenn eine Datei größer ist als 200kb kommt zwar die Msgbox mit dem Hinweis, ignoriert aber den Hinweis und fügt das Bild dennoch ein.

Wenn du prüfst, ist das Bild bereits eingefügt. Prüfe vor dem Einfügen.
Des Weiteren möchte ich noch gucken, ob is statt der .Left = Selection.Left auch ein .Center gibt.

Gibt's nicht. Musst du berechnen. Mitte = .Left + .Width/2
Gruß
Rudi

Anzeige
AW => Rudi: Bild in aktive Zelle einfügen
20.06.2013 10:31:38
Albert
Moin Rudi,
danke für deinen Hinweis! Ich hoff, mein Makroverständnis erlaubt mir das Umstellen des Codes für die Abbruchbedingung!
Merci und Gruß
A.

423 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige