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

Screenshot im UserForm

Screenshot im UserForm
30.11.2021 08:16:37
Andreas
Hallo,
kann mir jemand bei folgendem Problem helfen? Ich versuche von einem Tabellenblatt ein Screenshot in ein UserForm einzufügen.
Das mit dem Screenshot funktioniert. Aber wie bekomme ich das Bild jetzt in das UserForm? Alles was ich dazu gefunden und ausprobiert habe, hat nicht funktioniert.
Vielen Dank schon mal im voraus!
MfG Andreas

Private Sub UserForm_Initialize()
Application.ScreenUpdating = False
Range("A1:D5").CopyPicture Appearance:=xlScreen, Format:=xlPicture
ActiveSheet.Pictures.Paste
Application.ScreenUpdating = True
End Sub

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Screenshot im UserForm
30.11.2021 09:01:53
volti
Hallo Andreas,
teste mal folgendes Makro:
Code:

[Cc][+][-]

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 Declare PtrSafe Function EmptyClipboard 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 Dim hPic As LongPtr 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 einer Pic-Sammlung über die Zwischenablage ' in ein Userform-Control ein Dim oPict As IPictureDisp Dim tPicInfo As PIC_DESC, tID_IDispatch As GUID ' Bild aus Zwischenablage in das Image einfügen If IsClipboardFormatAvailable(CF_BITMAP) <> 0 Then If OpenClipboard(0&) <> 0 Then hPic = CopyImage(GetClipboardData(CF_BITMAP), _ IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG) CloseClipboard If hPic <> 0 Then With tID_IDispatch .Data1 = &H20400 .Data4(0) = &HC0 .Data4(7) = &H46 End With With tPicInfo .lSize = Len(tPicInfo) .lType = PICTYPE_BITMAP .hPic = hPic .hPal = 0 End With OleCreatePictureIndirect tPicInfo, tID_IDispatch, 0&, oPict If Not oPict Is Nothing Then ' ######### Hier die Userform und Image-Angaben anpassen ######## UserForm1.Image3.Picture = oPict Else MsgBox "Das Bild kann nicht angezeigt werden", vbCritical, "Bild einfügen" End If End If End If End If End Sub Sub Test() Range("A1:D5").Copy Paste_Picture_In_UF UserForm1.Show End Sub

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

Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige