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

Hardcopy in Image einfügen

Hardcopy in Image einfügen
06.07.2016 10:07:20
Fatih
Hallo Profis
Ich möchte eine Hardcopy vom Display mit Druck/S-Abf machen und diesen dann in der UserForm mit einem CommandButton im Image1 öffnen.
Ist dies möglich?
Gruß
Fatih

20
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Hardcopy in Image einfügen
06.07.2016 10:40:32
Fatih
Danke für deine schnelle Antwort Werner
leider komme ich da nicht weiter.
Gruß Fatih

AW: Hardcopy in Image einfügen
06.07.2016 12:26:33
Nepumuk
Hallo,
wie hast du dir den Ablauf denn vorgestellt? Und willst du den kompletten Bildschirm oder nur ein bestimmtes Fenster "fotografieren"?
Gruß
Nepumuk

Anzeige
AW: Hardcopy in Image einfügen
06.07.2016 12:32:06
Fatih
Hallo Nepumuk,
es soll ein Bereich vom Bildschirm fotografiert werden und dann in den Image Bereich in der Userform eingefügt werden.
Gruß
Fatih

AW: Hardcopy in Image einfügen
06.07.2016 12:55:14
Nepumuk
Hallo,
was für ein Bereich, einen Ausschnitt der Exceltabelle oder ein separates Fenster?
Gruß
Nepumuk

AW: Hardcopy in Image einfügen
06.07.2016 12:57:16
Fatih
Hallo,
ein separates Fenster
Gruß
Fatih

AW: Hardcopy in Image einfügen
06.07.2016 13:11:34
Nepumuk
Hallo,
dazu benötige ich den Klassennamen des Fensters und dessen Caption. Lass mal folgenden Code laufen und schreib mir was in Spalte B und C zu dem entsprechenden Fenster steht.
' **********************************************************************
' Modul: Modul4 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

Private Declare Function EnumWindows Lib "user32.dll" ( _
    ByVal lpEnumFunc As Long, _
    ByVal lParam As Long) As Boolean
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" ( _
    ByVal hwnd As Long, _
    ByVal lpString As String, _
    ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" ( _
    ByVal hwnd As Long) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" ( _
    ByVal hwnd As Long, _
    ByVal lpClassName As String, _
    ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" ( _
    ByVal hwnd As Long, _
    ByVal nIndex As Long) As Long

Private Const GWL_STYLE = (-16)
Private Const WS_VISIBLE = &H10000000
Private Const WS_BORDER = &H800000

Private llngRow As Long

Public Sub Start()
    llngRow = 1
    Columns("A:C").ClearContents
    With Range("A1:C1")
        .Value = Array("Hwnd", "Klasse", "Caption")
        .Font.Bold = True
    End With
    Call EnumWindows(AddressOf WindowCallBack, ByVal 0&)
    Columns("A:C").AutoFit
    Tabelle1.Sort.SortFields.Clear
    Tabelle1.Sort.SortFields.Add Key:=Columns(2)
    With Tabelle1.Sort
        .SetRange Columns("A:C")
        .Header = xlYes
        .MatchCase = False
        .Apply
    End With
End Sub

Private Function WindowCallBack(ByVal lngHwnd As Long, ByVal lngParam As Long) As Long
    Dim strCaption As String, strClassName As String
    Dim lngReturn As Long, lngStyle As Long
    lngStyle = GetWindowLong(lngHwnd, GWL_STYLE)
    If Cbool(lngStyle And (WS_VISIBLE Or WS_BORDER)) Then
        strClassName = Space$(256)
        lngReturn = GetClassName(lngHwnd, strClassName, 256)
        lngReturn = GetWindowTextLength(lngHwnd)
        strCaption = Space$(lngReturn)
        Call GetWindowText(lngHwnd, strCaption, lngReturn + 1)
        llngRow = llngRow + 1
        Cells(llngRow, 1).Resize(1, 3) = Array(lngHwnd, Trim$(strClassName), strCaption)
    End If
    WindowCallBack = 1
End Function

Gruß
Nepumuk

Anzeige
AW: Hardcopy in Image einfügen
06.07.2016 13:30:30
Fatih
jetzt kommt eine sau dumme frage von mir
ich bin schon selber von mir enttäuscht
Aber wo soll ich diesen Code einfügen?

AW: Hardcopy in Image einfügen
06.07.2016 13:34:19
Nepumuk
Hallo,
in ein Standardmodul einer neuen Mappe und dann die Routine Start starten. Das Ganze ist nur ein Hilfsprogramm um das Fenster, welches natürlich offen sein muss, zu klassifizieren.
Gruß
Nepumuk

AW: Hardcopy in Image einfügen
06.07.2016 13:15:35
Nepumuk
Hallo nochmal,
benutze diese Prozedur denn damit werden nur die sichtbaren Fenster aufgelistet:
' **********************************************************************
' Modul: Modul4 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

Private Declare Function EnumWindows Lib "user32.dll" ( _
    ByVal lpEnumFunc As Long, _
    ByVal lParam As Long) As Boolean
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" ( _
    ByVal hwnd As Long, _
    ByVal lpString As String, _
    ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" ( _
    ByVal hwnd As Long) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" ( _
    ByVal hwnd As Long, _
    ByVal lpClassName As String, _
    ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" ( _
    ByVal hwnd As Long, _
    ByVal nIndex As Long) As Long

Private Const GWL_STYLE = (-16)
Private Const WS_VISIBLE = &H10000000
Private Const WS_BORDER = &H800000

Private llngRow As Long

Public Sub Start()
    llngRow = 1
    Columns("A:C").ClearContents
    With Range("A1:C1")
        .Value = Array("Hwnd", "Klasse", "Caption")
        .Font.Bold = True
    End With
    Call EnumWindows(AddressOf WindowCallBack, ByVal 0&)
    Columns("A:C").AutoFit
    Tabelle1.Sort.SortFields.Clear
    Tabelle1.Sort.SortFields.Add Key:=Columns(2)
    With Tabelle1.Sort
        .SetRange Columns("A:C")
        .Header = xlYes
        .MatchCase = False
        .Apply
    End With
End Sub

Private Function WindowCallBack(ByVal lngHwnd As Long, ByVal lngParam As Long) As Long
    Dim strCaption As String, strClassName As String
    Dim lngReturn As Long, lngStyle As Long
    lngStyle = GetWindowLong(lngHwnd, GWL_STYLE)
    If (lngStyle And (WS_VISIBLE Or WS_BORDER)) = (WS_VISIBLE Or WS_BORDER) Then
        strClassName = Space$(256)
        lngReturn = GetClassName(lngHwnd, strClassName, 256)
        lngReturn = GetWindowTextLength(lngHwnd)
        strCaption = Space$(lngReturn)
        Call GetWindowText(lngHwnd, strCaption, lngReturn + 1)
        llngRow = llngRow + 1
        Cells(llngRow, 1).Resize(1, 3) = Array(lngHwnd, Trim$(strClassName), strCaption)
    End If
    WindowCallBack = 1
End Function

Gruß
Nepumuk

Anzeige
AW: Hardcopy in Image einfügen
06.07.2016 13:47:20
Fatih
hab es eingefügt
bekomme aber diese Meldung
https://www.herber.de/bbs/user/106798.jpg
Sub Schaltfläche11_Click()
End Sub
Option Explicit
Private Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal  _
lParam As Long) As Boolean
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As  _
Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" ( _
ByVal hwnd As Long) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As  _
Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As  _
Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_VISIBLE = &H10000000
Private Const WS_BORDER = &H800000
Private llngRow As Long
Public Sub Start()
llngRow = 1
Columns("A:C").ClearContents
With Range("A1:C1")
.Value = Array("Hwnd", "Klasse", "Caption")
.Font.Bold = True
End With
Call EnumWindows(AddressOf WindowCallBack, ByVal 0&)
Columns("A:C").AutoFit
Tabelle1.Sort.SortFields.Clear
Tabelle1.Sort.SortFields.Add Key:=Columns(2)
With Tabelle1.Sort
.SetRange Columns("A:C")
.Header = xlYes
.MatchCase = False
.Apply
End With
End Sub
Private Function WindowCallBack(ByVal lngHwnd As Long, ByVal lngParam As Long) As Long
Dim strCaption As String, strClassName As String
Dim lngReturn As Long, lngStyle As Long
lngStyle = GetWindowLong(lngHwnd, GWL_STYLE)
If (lngStyle And (WS_VISIBLE Or WS_BORDER)) = (WS_VISIBLE Or WS_BORDER) Then
strClassName = Space$(256)
lngReturn = GetClassName(lngHwnd, strClassName, 256)
lngReturn = GetWindowTextLength(lngHwnd)
strCaption = Space$(lngReturn)
Call GetWindowText(lngHwnd, strCaption, lngReturn + 1)
llngRow = llngRow + 1
Cells(llngRow, 1).Resize(1, 3) = Array(lngHwnd, Trim$(strClassName), strCaption)
End If
WindowCallBack = 1
End Function
End Sub

Anzeige
AW: Hardcopy in Image einfügen
06.07.2016 15:42:14
Nepumuk
Hallo,
war das Fenster welches fotografiert werden soll offen? Denn angezeigt wird es nicht.
Gruß
Nepumuk

AW: Hardcopy in Image einfügen
07.07.2016 09:59:39
Fatih
Hallo Nepumuk
Also ich öffne das Programm SnippingTool und wähle ein x beliebigen Bereich aus.
Dieser wandert ja meines Wissens in den Zwischenspeicher.
Diesen möchte ich dann in die UserForm1 Image1 einfügen.
und genau da hängts bei mir.

Anzeige
AW: Hardcopy in Image einfügen
07.07.2016 11:17:40
Fatih
Ich hab es mit diesem Code versucht.
Jedoch bekomme ich eine Fehlermeldung beim fett markierten Bereich.
Fehler beim Komplieren: Typen Unverträglich
If My.Computer.Clipboard.ContainsImage() Then
Dim grabpicture As System.Drawing.Image
grabpicture = My.Computer.Clipboard.GetImage()
PictureBox1.Image = grabpicture
End If

AW: Hardcopy in Image einfügen
07.07.2016 11:25:00
Nepumuk
Hallo,
das ist ein Code aus VB.net der kann in Excel nicht funktionieren.
Test mal das:
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 Show_Clipboard()
    
    Dim objPicture As IPictureDisp
    
    Set objPicture = Paste_Picture()
    
    If Not objPicture Is Nothing Then
        Set UserForm1.Image1.Picture = objPicture
    Else
        Call MsgBox("Error - Chlipboard can't show in Userform", vbCritical, "Error")
    End If
    
    Call UserForm1.Show
    
    Call DeleteObject(llngptrCopy)
    
End Sub


Gruß
Nepumuk

Anzeige
AW: Hardcopy in Image einfügen
07.07.2016 11:50:58
Fatih
Bei mir kommt
Fehler beim Kompilieren:
Nach End Sub, End Function oder End Property können nur Kommentare stehen.
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
Gruß
Fatih

AW: Hardcopy in Image einfügen
07.07.2016 12:03:55
Nepumuk
Hallo,
das kopieren von Code müssen wir noch üben.
https://www.herber.de/bbs/user/106832.xlsm
Gruß
Nepumuk

Anzeige
AW: Hardcopy in Image einfügen
07.07.2016 13:11:19
Fatih
Danke dir Nepumuk
klappt zwar noch nicht alles ganz so wie ich es mir vorstelle, aber ich hab jetzt dank dir ein Fundamet worauf ich aufbauen kann.
Danke nochmals
Gruß
Fatih

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige