Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1484to1488
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 Export - schlechte Qualität

Bild Export - schlechte Qualität
30.03.2016 18:51:25
Rudolf

Hallo Zusammen
Ich habe für mein Büro ein Userform eingerichtet, bei dem nach einem click die erfassten Daten in eine Template Tabelle eingefügt werden und gleichzeitig ein Email generiert und das Template-Bereich als Bild(ChartObject) in das Email kopiert wird.
Nur leider wirkt das Bild verschwommen im Email und das sieht nicht so schön aus.
Gleichzeitig möchte ich das Bild mit verkleinern damit es besser aussieht.
Wie kriege ich es hin, dass das Bild bzw. Chart Object welche der Code aus eine template Tabelle rauskopiert auch wirklich hochauflösend im Email aussieht?
Ich habe den u.a. Code als Modul, welches beim CLICK auf den Command Button per Call ausgeführt wird

Sub Email()
' Export Range as JPG file
' Set Range you want to export to file
Dim r As Range
Dim co As ChartObject
Dim picFile As String
Set r = Tabelle4.Range("B2:F42")
' Copy range as picture onto Clipboard
r.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
picFile = Environ("Temp") & "\TempExportChart.jpg"
' Create an empty chart with exact size of range copied
Set co = r.Parent.ChartObjects.Add(Left:=r.Left, Top:=r.Top, Width:=r.Width, Height:=r. _
Height)
With co
' Paste into chart area, export to file, delete chart.
.Chart.Paste
.Chart.Export picFile
.Delete
End With
' Create Email and Import Picture
' Send out the email
Dim OutApp As Object
Set OutApp = CreateObject("Outlook.Application")
Dim OutMail As Object
Set OutMail = OutApp.CreateItem(olMailItem)
Dim signature As String
Dim tstamp As String
Dim strBody As String
' Subject location
OutMail.Display
signature = OutMail.HTMLBody
' Change change email list here
strBody = "Dear Collegues 
We will execute following trade
Bewerten Sie hier bitte das Excel-Portal
Best regards
Value _ Team" On Error Resume Next With OutMail .To = Tabelle4.Range("I2") .CC = Tabelle4.Range("I3") .BCC = Tabelle4.Range("I4") .Subject = Tabelle4.Range("I5") .HTMLBody = strBody & vbNewLine & signature .Attachments.Add Sheets("Save and Send").Range("D4") & Sheets("Save and Send").Range(" _ _ D23") ' attaching the pdf End With Kill picFile On Error GoTo 0 'Tidy Up Set OutMail = Nothing Set OutApp = Nothing Set co = Nothing Set r = Nothing End Sub

8
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Bild Export - schlechte Qualität
31.03.2016 16:24:23
Nepumuk
Hallo,
schau mal ob die Qualität damit besser ist. Vom verkleinern würde ich abraten denn das macht das Bild nicht besser.
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

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
Size As Long
Type 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 llngptrCopy As LongPtr

Private Function Paste_Picture() As IPictureDisp
    
    Dim lngReturn As Long, lngptrPointer As LongPtr
    
    If Cbool(IsClipboardFormatAvailable(CF_BITMAP)) Then
        
        lngReturn = OpenClipboard(Application.hwnd)
        
        If lngReturn > 0 Then
            
            lngptrPointer = GetClipboardData(CF_BITMAP)
            
            llngptrCopy = CopyImage(lngptrPointer, _
                IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG)
            
            Call CloseClipboard
            
            If lngptrPointer <> 0 Then Set Paste_Picture = _
                Create_Picture(llngptrCopy, 0&)
            
        End If
    End If
End Function

Private Function Create_Picture( _
        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
        .Size = Len(udtPicInfo)
        .Type = PICTYPE_BITMAP
        .hPic = lngptrhPic
        .hPal = lngptrhPal
    End With
    
    Call OleCreatePictureIndirect(udtPicInfo, _
        udtID_IDispatch, 0, objPicture)
    
    Set Create_Picture = objPicture
    
    Set objPicture = Nothing
    
End Function

Public Sub SaveRange()
    
    Dim objPicture As IPictureDisp
    
    Call OpenClipboard(Application.hwnd)
    Call EmptyClipboard
    Call CloseClipboard
    
    Call Tabelle1.Range("B2:F42").CopyPicture( _
        Appearance:=xlScreen, Format:=xlBitmap)
    
    Set objPicture = Paste_Picture()
    
    If Not objPicture Is Nothing Then
        Call SavePicture(objPicture, Environ$("Temp") & "\TempExport.bmp")
    Else
        Call MsgBox("Error - Picture can't saved", vbCritical, "Error")
    End If
    
    Call DeleteObject(llngptrCopy)
    
    Set objPicture = Nothing
    
End Sub

Gruß
Nepumuk

Anzeige
AW: Bild Export - schlechte Qualität
02.04.2016 21:35:04
Rudolf
Hallo Nepumuk
Wie muss ich diesen Code einbinden?
Kann das als Modul und danach beim CommandButton als Call abrufen??
Danke und Grüsse
Rudi

AW: Bild Export - schlechte Qualität
02.04.2016 21:55:58
Nepumuk
Hallo,
teste es doch erst mal.
Gruß
Nepumuk

AW: Bild Export - schlechte Qualität
03.04.2016 13:47:15
Rudolf
Hallöchen,
Würde ich gern testen, weiss jedoch nicht wie :-).
Überschreibe ich das alte Modul mit dem neuen Code kommt eine Kompilierungsfehlermeldung. Ich komme also nicht zum testen da ich nicht weiss wie diesen Code zu behandeln :(
Grüsse
Rudi

AW: Bild Export - schlechte Qualität
03.04.2016 13:57:45
Nepumuk
Hallo,
kopiere ihn in eine neue Mappe füll ein paar Zellen im Bereich B2:F42, starte die Routine SaveRange und schau dir das Ergebnis (findest du im Temp-Ordner) an.
Gruß
Nepumuk

Anzeige
AW: Bild Export - schlechte Qualität
03.04.2016 16:21:51
Rudolf
Es klappt leider nicht :(
im Temp Ordner liegt nichts vor...
verzweifle fast.. hab derart viel Zeit investiert in meine File und nun scheitert es an der minderwertigen Bildqualität :( - kann es sein, dass es am export bzw. Import ins Outlook liegt?
Grüsse

AW: Bild Export - schlechte Qualität
03.04.2016 21:38:40
Rudolf
jemand ne idee? :)
Grazie 1000

AW: Bild Export - schlechte Qualität
04.04.2016 13:37:07
Nepumuk
Hallo,
dann ändere doch hier:
Call SavePicture(objPicture, Environ$("Temp") & "\TempExport.bmp")
mal den Ausgabepfad damit du das Bild wiederfindest. Denn wenn keine Fehlermeldung angezeigt wird, dann wurde das Bild auch gespeichert, nur du findest es nicht.
Gruß
Nepumuk

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige