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

Export vom Tabellenbereich in Userform

Export vom Tabellenbereich in Userform
23.12.2022 07:48:00
Sebastian
Hallo Profis,
ich möchte gerne einen Tabellenbereich in eineme Userform anzeigen lassen. Das soll ja mittels Export in ein Bild und wieder einlesen gehen. Leider bleibt beim Export das Bild immer nur weiß :-( Die Tabelle stimmt aber.
Was mache ich falsch - hat jemand eine Idee?
Hier mein Code

Private Sub CommandButton1_Click()
Dim chDiagramm As ChartObject
Dim picBild As Picture
Application.ScreenUpdating = False
Sheets("Tabelle1").Range("A1:E8").CopyPicture Appearance:=xlScreen, Format:=xlPicture
Set picBild = ActiveSheet.Pictures.Paste
picBild.CopyPicture Appearance:=xlScreen, Format:=xlPicture
Set chDiagramm = ActiveSheet.ChartObjects.Add(0, 0, picBild.Width, picBild.Height)
With chDiagramm.Chart
.Paste
.Export FileName:="C:\Temp\Bild.jpg", FilterName:="JPG" ' andere Grafikformate sind möglich
End With
If Not Me.Image1.Picture Is Nothing Then
Image1.Picture = Nothing
End If
Image1.Picture = LoadPicture("C:\Temp\Bild.jpg")
DoEvents
chDiagramm.Delete
Kill "C:\Temp\Bild.jpg"
picBild.Delete
Set chDiagramm = Nothing
Set picBild = Nothing
Application.ScreenUpdating = True
End Sub

3
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Export vom Tabellenbereich in Userform
23.12.2022 08:43:28
volti
Hallo Sebastian,
falls niemand eine Idee zur Abhilfe hat, hier eine Alternative, bei der Bereich direkt als Bild eingefügt wird.
Code:


Option Explicit Private Declare PtrSafe Function OleCreatePictureIndirect Lib "oleaut32.dll" ( _ ByRef PicDesc As PIC_DESC, ByRef RefIID As GUID, _ ByVal fPictureOwnsHandle As LongPtr, ByRef IPic As IPictureDisp) As Long Private Declare PtrSafe Function CopyImage Lib "user32" ( _ 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" ( _ ByVal wFormat As Long) As Long Private Declare PtrSafe Function GetClipboardData Lib "user32" ( _ ByVal wFormat As Long) As LongPtr Private Declare PtrSafe Function OpenClipboard Lib "user32" ( _ ByVal hWnd As LongPtr) As Long Private Declare PtrSafe Function CloseClipboard Lib "user32" () As Long Private Type GUID Data1 As Long Data2 As Integer Data3 As Integer Data4(0 To 7) As Byte End Type Private Type PIC_DESC lSize As Long lType As Long hPic As LongPtr hPal As LongPtr End Type Private Const PICTYPE_BITMAP = 1 Private Const CF_BITMAP = 2 Private Const IMAGE_BITMAP = 0 Private Const LR_COPYRETURNORG = &H4 Sub Paste_Picture_In_UF() ' Fügt ein Bild aus aus der Zwischenablage in ein Userform-Control ein Dim oPict As IPictureDisp Dim tPicInfo As PIC_DESC, tID_IDispatch As GUID If IsClipboardFormatAvailable(CF_BITMAP) <> 0 Then If OpenClipboard(0&) <> 0 Then With tID_IDispatch .Data1 = &H20400 .Data4(0) = &HC0 .Data4(7) = &H46 End With With tPicInfo .lSize = LenB(tPicInfo) .lType = PICTYPE_BITMAP .hPic = CopyImage(GetClipboardData(CF_BITMAP), _ IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG) CloseClipboard If .hPic <> 0 Then _ OleCreatePictureIndirect tPicInfo, tID_IDispatch, 0&, oPict End With If Not oPict Is Nothing Then ' ######### Hier die Userform und Image-Angaben anpassen ######## UserForm1.Image1.Picture = oPict Else MsgBox "Das Bild kann nicht angezeigt werden", vbCritical, "Bild einfügen" End If End If End If End Sub Sub Test() ThisWorkbook.Sheets("Tabelle1").Range("A1:E8").Copy DoEvents Paste_Picture_In_UF UserForm1.Show End Sub

_________________________
viele Grüße aus Freigericht 😊
Karl-Heinz

Anzeige
AW: Export vom Tabellenbereich in Userform
23.12.2022 09:04:47
Sebastian
Hallo Karl Heinz,
das funktioniert einwandfrei aber leider nur in einem neuem Userform.
In meinem Userform, ich gebe zu das ist schon extrem "Bealden" bekomme ich ("Internen fehler") an der Stelle "Dim tPicInfo As PIC_DESC"
Ansonsten würde ich diese Variante dem Export sogar bevorzugen.
Hast Du noch eine Idee?
AW: Export vom Tabellenbereich in Userform
23.12.2022 09:10:26
Sebastian
Keine Ahung warum aber es war das "Option Explicit" ganz oben - war sicher doppelt obwohl dein Code in einem Extra Modul war.
Ich danke dir von Herzen.
Viele Grüße

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige