Anzeige
Archiv - Navigation
1828to1832
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 von Tabellenblat in Mail einfügen

Bild von Tabellenblat in Mail einfügen
07.05.2021 11:07:37
Tabellenblat
Hallo Profis,
ich erstelle mit VBA eine HTML mail und möchte nun gerne ein Bild welches auf einem Tabellenblatt ist in die Mail einfügen.
Im Moment mache ich das schon mit einem Bild welches auf dem Laufwerk gespeichert ist
pfad = "c:\test.jpg"

Das funktioniert auch,
Aber kann ich auch das Bild in einem Tabellenblatt mit einfügen
Tabelle1.Image1 ?
Das klappt natürlich nicht mit dem Pfad. Zwischenspeichern kann ich leider auch nicht. Geht das auch ohne?
Vielen Dank und viele Grüße
Sebastian

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Bild von Tabellenblat in Mail einfügen
07.05.2021 11:41:12
Tabellenblat
Hallo Sebastian,
speichere das Bild aus dem Tabellenblatt einfach an deinem Wunschort, und packe es von dort aus wie bisher in die Mail.

Sub test()
Dim objPict As Object, objChrt As Chart
Dim strFile As String
On Error GoTo ErrExit
With ActiveSheet
.Activate
.Shapes("Grafik 10").CopyPicture Appearance:=xlScreen, Format:=xlBitmap
.PasteSpecial Format:="Bitmap", Link:=False, DisplayAsIcon:=False
Set objPict = .Shapes(.Shapes.Count)
strFile = "C:\Temp\MeinBild.jpg"
objPict.Copy
Set objChrt = .ChartObjects.Add(1, 1, objPict.Width + 8, objPict.Height + 8).Chart
.ChartObjects(Replace(objChrt.Name, ActiveSheet.Name & " ", "")).Activate
ActiveChart.Paste
objChrt.Export strFile
objChrt.Parent.Delete
objPict.Delete
End With
ErrExit:
Set objPict = Nothing
Set objChrt = Nothing
End Sub
LG,
Klaus M.
Anzeige
AW: Bild von Tabellenblat in Mail einfügen
07.05.2021 12:10:40
Tabellenblat
Ok Das klappt eigentlich, Vielen Dank schonmal. Nur bekomme ich einen Rahmen um das Bild :-(
Kann man das auch ohne Rahmen exportieren?
VBA "ChartObject" Rahmen entfernen?
07.05.2021 12:15:30
Klaus
Hallo Sebastian,
ich bin mir 99% sicher, der Rahmen liegt am "ChartObject". Da man ein Chart ohne Rahmen darstellen kann, kann man es bestimmt auch ohne Rahmen exportieren. Wie exakt der VBA-Syntax dafür lautet kann ich dir nicht sagen, in Pseudocode wäre es etwa:
ActiveChart.Borders = False
vor dem Export und nach dem Paste.
Ich lass mal offen. Vielleicht schaut Beverly vorbei, die kann alle VBA-Chart Befehle im Schlaf :-)
LG,
Klaus M.
Anzeige
AW: Bild von Tabellenblat in Mail einfügen
07.05.2021 12:23:59
Tabellenblat
Hallo Sebastian,
teste mal:
Code:

[Cc][+][-]

Option Explicit Private Declare PtrSafe Function OleCreatePictureIndirect Lib "oleaut32.dll" ( _ ByRef PicDesc As PICT_DESC, _ ByRef RefIID As GUID, _ ByVal fPictureOwnsHandle As LongPtr, _ ByRef IPic As IPicture) As LongPtr Private Declare PtrSafe Function CopyImage Lib "user32.dll" ( _ ByVal handle As LongPtr, _ ByVal un1 As Long, _ ByVal n1 As Long, _ ByVal n2 As Long, _ ByVal un2 As Long) As LongPtr Private Declare PtrSafe Function IsClipboardFormatAvailable Lib "user32.dll" ( _ ByVal wFormat As Long) As Long Private Declare PtrSafe Function OpenClipboard Lib "user32.dll" ( _ ByVal hwnd As LongPtr) As Long Private Declare PtrSafe Function GetClipboardData Lib "user32.dll" ( _ ByVal wFormat As Long) As LongPtr Private Declare PtrSafe Function DeleteObject Lib "gdi32.dll" ( _ ByVal hObject As LongPtr) As Long Private Declare PtrSafe Function CLSIDFromString Lib "ole32.dll" ( _ ByVal lpsz As Any, _ ByRef pCLSID As GUID) As Long Private Declare PtrSafe Function EmptyClipboard Lib "user32.dll" () As Long Private Declare PtrSafe Function CloseClipboard Lib "user32.dll" () As Long Private Type GUID Data1 As Long Data2 As Integer Data3 As Integer Data4(0 To 7) As Byte End Type Private Type PICT_DESC lSize As Long lType As Long hPic As LongPtr hPal As LongPtr End Type Private Const PICTYPE_BITMAP As Long = 1 Private Const CF_BITMAP As Long = 2 Private Const IMAGE_BITMAP As Long = 0 Private Const LR_COPYRETURNORG As Long = &H4 Private Const GUID_IPICTUREDISP As String = "{7BF80981-BF32-101A-8BBB-00AA00300CAB}" Private Function PastePicture(ByRef prlngptrCopy As LongPtr) As IPictureDisp Dim lngReturn As Long, lngptrPointer As LongPtr If CBool(IsClipboardFormatAvailable(CF_BITMAP)) Then lngReturn = OpenClipboard(CLngPtr(Application.hwnd)) If lngReturn > 0 Then lngptrPointer = GetClipboardData(CF_BITMAP) prlngptrCopy = CopyImage(lngptrPointer, _ IMAGE_BITMAP, 0&, 0&, LR_COPYRETURNORG) Call CloseClipboard If lngptrPointer <> 0 Then Set PastePicture = _ CreatePicture(prlngptrCopy, 0) End If End If End Function Private Function CreatePicture( _ ByVal lngptrhPic As LongPtr, _ ByVal lngptrhPal As LongPtr) As IPictureDisp Dim udtPicInfo As PICT_DESC, udtID_IDispatch As GUID Dim objPicture As IPictureDisp Call CLSIDFromString(StrPtr( _ GUID_IPICTUREDISP), udtID_IDispatch) With udtPicInfo .lSize = Len(udtPicInfo) .lType = PICTYPE_BITMAP .hPic = lngptrhPic .hPal = lngptrhPal End With Call OleCreatePictureIndirect(udtPicInfo, _ udtID_IDispatch, 0&, objPicture) Set CreatePicture = objPicture Set objPicture = Nothing End Function Public Sub SaveShape() Dim lngptrCopy As LongPtr Dim objPicture As IPictureDisp Call OpenClipboard(0) Call EmptyClipboard Call CloseClipboard On Error Resume Next Do ActiveSheet.Shapes(1).CopyPicture _ Appearance:=xlScreen, Format:=xlBitmap If Err.Number = 0 Then Exit Do Call Err.Clear Loop On Error GoTo 0 DoEvents Do Set objPicture = PastePicture(lngptrCopy) Loop While objPicture Is Nothing If objPicture Is Nothing Then MsgBox "Picture can't store on Drive", vbCritical, "Error" Else Call SavePicture(Picture:=objPicture, Filename:=ThisWorkbook.Path & "&bsol;Temp.bmp") End If Call DeleteObject(lngptrCopy) End Sub

Gruß
Nepumuk
Anzeige
AW: Bild von Tabellenblat in Mail einfügen
07.05.2021 12:32:53
Tabellenblat
Das klappt - Ganz schön lang der Code aber geht :-) Vielen Dank an euch beide

330 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige