Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1416to1420
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
Print Microsoft Web Browser Fenster
08.04.2015 11:58:55
Nicolaus
Hallo zusammen,
ich habe folgendes Problem:
Habe ein Microsoft Web Browser Fenster in meinem Sheet, welches über einen ActiveX Button verlinkt eine URL (Google Maps) darstellt.
Das läuft soweit alles gut, nur wenn ich den Spaß jetzt drucken will, druckt er das Microsoft Web Browser Fenster nicht.
Im Folgenden ein Foto.
Userbild
Danke im Voraus und beste Grüße,
Nico

16
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Print Microsoft Web Browser Fenster
08.04.2015 12:14:55
Nepumuk
Hallo,
alle Controls die nicht aus der FM20.dll stammen haben das Problem und daran wird Microsoft auch nichts ändern. Du könntest den Webbrowser auf selbst ausdrucken. Dann hast du aber die restlichen Informationen nicht auf dem ausgedruckten Blatt.
Gruß
Nepumuk

AW: Print Microsoft Web Browser Fenster
08.04.2015 12:20:08
Nicolaus
Danke für die schnelle Antwort!
Irgend eine Idee, wie ich das umgehen kann? Gibt es evtl eine andere Möglichkeit, wie ich eine dynamische Map erstellen und zusammen mit anderen Infos auf dem Sheet drucken kann?
Danke!

AW: Print Microsoft Web Browser Fenster
08.04.2015 12:27:14
Nepumuk
Hallo,
das Webbrowser-Control auf ein UserForm und nach dem laden der Seite einen Screenshot des UserForms als Bild in die Tabelle einfügen. Benötigt aber ein bisschen API-Zauber.
Gruß
Nepumuk

Anzeige
AW: Print Microsoft Web Browser Fenster
08.04.2015 12:30:49
Nicolaus
Zaubern kann ich noch nicht und API sagt mir auch leider nichts. Aber ich lese mich mal schlau. Danke! ;)

AW: Print Microsoft Web Browser Fenster
08.04.2015 14:48:31
Nepumuk
Hallo,
für mal den Webbrowser in ein UserForm ein, so dass die gesamte Fläche des UserForms damit gefüllt ist. In das Modul des UserForms folgenden Code:
' **********************************************************************
' Modul: UserForm1 Typ: Userform
' **********************************************************************

Option Explicit

Private Declare PtrSafe Sub Sleep Lib "kernel32.dll" ( _
    ByVal dwMilliseconds As Long)
Private Declare PtrSafe Function FindWindowA Lib "user32.dll" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function GetWindowLongA Lib "user32.dll" ( _
    ByVal hwnd As LongPtr, _
    ByVal nIndex As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLongA Lib "user32.dll" ( _
    ByVal hwnd As LongPtr, _
    ByVal nIndex As Long, _
    ByVal dwNewLong As LongPtr) As LongPtr
Private Declare Function DrawMenuBar Lib "user32.dll" ( _
    ByVal hwnd As LongPtr) As Long
Private Declare Function IsThemeActive Lib "UxTheme.dll" () As Long

Private Const GC_CLASSNAMEUSERFORM = "ThunderDFrame"
Private Const GWL_STYLE = -16&
Private Const WS_CAPTION = &HC00000
Private Const HTCAPTION = 2&
Private Const WM_NCLBUTTONDOWN = &HA1

Private Sub UserForm_Activate()
    
    Dim udtRectangle As RECT
    Dim lngptrForm As LongPtr, lngptrStyle As LongPtr
    
    Call WebBrowser1.Navigate2("http://www.herber.de/forum/")
    
    lngptrForm = FindWindowA(GC_CLASSNAMEUSERFORM, Caption)
    
    If lngptrForm <> 0 Then
        lngptrStyle = GetWindowLongA(lngptrForm, GWL_STYLE)
        lngptrStyle = lngptrStyle And Not WS_CAPTION
        Call SetWindowLongA(lngptrForm, GWL_STYLE, lngptrStyle)
        Call DrawMenuBar(lngptrForm)
        Height = Height - IIf(Cbool(IsThemeActive), 20, 18)
    End If
    
    
    Do
        Call Sleep(100)
        DoEvents
    Loop While WebBrowser1.Busy
    
    Do
        Call Sleep(100)
        DoEvents
    Loop Until WebBrowser1.ReadyState = READYSTATE_COMPLETE
    
    With udtRectangle
        .Left = Left / 0.75
        .Top = Top / 0.75
        .Right = (Left + Width) / 0.75
        .Bottom = (Top + Height) / 0.75
    End With
    
    Call Save_Picture(udtRectangle)
    
    Call Unload(Me)
    
End Sub

In ein Standardmodul kommt folgender Code:
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

Private Declare PtrSafe Function CreateCompatibleDC Lib "gdi32.dll" ( _
    ByVal hdc As LongPtr) As LongPtr
Private Declare PtrSafe Function CreateCompatibleBitmap Lib "gdi32.dll" ( _
    ByVal hdc As LongPtr, _
    ByVal nWidth As Long, _
    ByVal nHeight As Long) As LongPtr
Private Declare PtrSafe Function SelectObject Lib "gdi32.dll" ( _
    ByVal hdc As LongPtr, _
    ByVal hObject As LongPtr) As LongPtr
Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32.dll" ( _
    ByVal hdc As LongPtr, _
    ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetSystemPaletteEntries Lib "gdi32.dll" ( _
    ByVal hdc As LongPtr, _
    ByVal wStartIndex As Long, _
    ByVal wNumEntries As Long, _
    ByRef lpPaletteEntries As PALETTEENTRY) As Long
Private Declare PtrSafe Function CreatePalette Lib "gdi32.dll" ( _
    lpLogPalette As LOGPALETTE) As LongPtr
Private Declare PtrSafe Function SelectPalette Lib "gdi32.dll" ( _
    ByVal hdc As LongPtr, _
    ByVal hPalette As LongPtr, _
    ByVal bForceBackground As Long) As LongPtr
Private Declare PtrSafe Function RealizePalette Lib "gdi32.dll" ( _
    ByVal hdc As LongPtr) As Long
Private Declare PtrSafe Function BitBlt Lib "gdi32.dll" ( _
    ByVal hDestDC As LongPtr, _
    ByVal x As Long, _
    ByVal y As Long, _
    ByVal nWidth As Long, _
    ByVal nHeight As Long, _
    ByVal hSrcDC As LongPtr, _
    ByVal xSrc As Long, _
    ByVal ySrc As Long, _
    ByVal dwRop As Long) As Long
Private Declare PtrSafe Function DeleteDC Lib "gdi32.dll" ( _
    ByVal hdc As LongPtr) As Long
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 OleCreatePictureIndirect Lib "olepro32.dll" ( _
    ByRef PicDesc As PIC_DESC, _
    ByRef RefIID As GUID, _
    ByVal fPictureOwnsHandle As Long, _
    ByRef IPic As IPictureDisp) As Long
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 GetDC Lib "user32.dll" ( _
    ByVal hwnd As LongPtr) As LongPtr
Private Declare PtrSafe Function OpenClipboard Lib "user32.dll" ( _
    ByVal hwnd As LongPtr) As Long
Private Declare PtrSafe Function SetClipboardData Lib "user32.dll" ( _
    ByVal wFormat As Long, _
    ByVal hMem As LongPtr) As LongPtr
Private Declare PtrSafe Function IsClipboardFormatAvailable Lib "user32.dll" ( _
    ByVal wFormat As Long) As Long
Private Declare PtrSafe Function GetClipboardData Lib "user32.dll" ( _
    ByVal wFormat As Long) As LongPtr
Private Declare PtrSafe Function EmptyClipboard Lib "user32.dll" () As Long
Private Declare PtrSafe Function CloseClipboard Lib "user32.dll" () As Long
Private Declare PtrSafe Sub Sleep Lib "kernel32.dll" ( _
    ByVal dwMilliseconds As Long)

Public Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Type PALETTEENTRY
    peRed As Byte
    peGreen As Byte
    peBlue As Byte
    peFlags As Byte
End Type

Private Type LOGPALETTE
    palVersion As Integer
    palNumEntries As Integer
    palPalEntry(255) As PALETTEENTRY
End Type

Private Type GUID
    Data1 As Long
    Data2 As Integer
    Data3 As Integer
    Data4(0 To 7) As Byte
End Type

Private Type PIC_DESC
    lngSize As Long
    lngType As Long
    lnghPic As Long
    lnghPal As Long
End Type

Private Const RASTERCAPS As Long = 38&
Private Const RC_PALETTE As Long = &H100&
Private Const SIZEPALETTE As Long = 104&
Private Const SRCCOPY As Long = &HCC0020
Private Const CF_BITMAP As Long = 2&
Private Const IMAGE_BITMAP As Long = 0&
Private Const LR_COPYRETURNORG As Long = &H4&
Private Const PICTYPE_BITMAP As Long = 1&
Private Const GUID_IPICTUREDISP As String = "{7BF80981-BF32-101A-8BBB-00AA00300CAB}"

Public Sub Save_Picture(ByRef prudtRectangle As RECT)
    
    Dim lngptrCopyHandle As LongPtr
    Dim strFileName As String
    Dim objPicture As IPictureDisp
    
    Call OpenClipboard(CLngPtr(Application.hwnd))
    Call EmptyClipboard
    Call SetClipboardData(CF_BITMAP, DC_To_Picture(prudtRectangle))
    Call CloseClipboard
    
    Set objPicture = Paste_Picture(lngptrCopyHandle)
    
    If Not objPicture Is Nothing Then
        
        strFileName = ThisWorkbook.Path & "\TempPicture.bmp"
        
        Call SavePicture(objPicture, strFileName)
        
        Set objPicture = Nothing
        
        Call DeleteObject(lngptrCopyHandle)
        
        With Tabelle1
            Call .Shapes.AddPicture(strFileName, msoFalse, msoTrue, _
                .Cells(3.3).Left, .Cells(3, 3).Top, -1, -1)
        End With
        
    Else
        
        Call Err.Raise(Number:=vbObjectError & 1004&, _
            Description:="Feher beim Erstellen des Bildes.")
        
    End If
End Sub

Private Function DC_To_Picture( _
        ByRef prudtRect As RECT) As LongPtr

    
    Dim lngLeftSrc As Long, lngTopSrc As Long, lngWidthSrc As Long, lngHeightSrc As Long
    Dim lngprthDCMemory As LongPtr, lngptrhBmp As LongPtr
    Dim lngptrhPal As LongPtr, lngptrhPalPrev As LongPtr, lngptrhBmpPrev As LongPtr
    Dim lngRasterCapsScrn As Long, lngptrhDCScr As LongPtr
    Dim lngHasPaletteScrn As Long, lngPaletteSizeScrn As Long
    Dim udtLogPal As LOGPALETTE
    
    lngLeftSrc = prudtRect.Left
    lngTopSrc = prudtRect.Top
    lngWidthSrc = prudtRect.Right - prudtRect.Left
    lngHeightSrc = prudtRect.Bottom - prudtRect.Top
    
    lngptrhDCScr = GetDC(0)
    
    lngprthDCMemory = CreateCompatibleDC(lngptrhDCScr)
    lngptrhBmp = CreateCompatibleBitmap(lngptrhDCScr, lngWidthSrc, lngHeightSrc)
    lngptrhBmpPrev = SelectObject(lngprthDCMemory, lngptrhBmp)
    lngRasterCapsScrn = GetDeviceCaps(lngptrhDCScr, RASTERCAPS)
    lngHasPaletteScrn = lngRasterCapsScrn And RC_PALETTE
    lngPaletteSizeScrn = GetDeviceCaps(lngptrhDCScr, SIZEPALETTE)
    
    If lngHasPaletteScrn And (lngPaletteSizeScrn = &H100&) Then
        udtLogPal.palVersion = &H300&
        udtLogPal.palNumEntries = &H100&
        Call GetSystemPaletteEntries(lngptrhDCScr, 0&, _
            &H100&, udtLogPal.palPalEntry(0&))
        lngptrhPal = CreatePalette(udtLogPal)
        lngptrhPalPrev = SelectPalette(lngprthDCMemory, lngptrhPal, 0&)
        Call RealizePalette(lngprthDCMemory)
    End If
    
    Call BitBlt(lngprthDCMemory, 0&, 0&, lngWidthSrc, lngHeightSrc, _
        lngptrhDCScr, lngLeftSrc, lngTopSrc, SRCCOPY)
    
    lngptrhBmp = SelectObject(lngprthDCMemory, lngptrhBmpPrev)
    
    If lngHasPaletteScrn And (lngPaletteSizeScrn = 256&) Then _
        lngptrhPal = SelectPalette(lngprthDCMemory, lngptrhPalPrev, 0&)
    
    Call DeleteDC(lngprthDCMemory)
    
    DC_To_Picture = lngptrhBmp
    
End Function

Private Function Paste_Picture(ByRef prlngptrCopyHandle 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)
            
            prlngptrCopyHandle = CopyImage(lngptrPointer, _
                IMAGE_BITMAP, 0&, 0&, LR_COPYRETURNORG)
            
            Call CloseClipboard
            
            If lngptrPointer <> 0 Then Set Paste_Picture = _
                Create_Picture(prlngptrCopyHandle, 0&, CF_BITMAP)
            
        End If
    End If
End Function

Private Function Create_Picture( _
        ByVal lnghPic As Long, _
        ByVal lnghPal As Long, _
        ByVal lngPicType As Long) As IPictureDisp

    
    Dim udtPicInfo As PIC_DESC, udtID_IDispatch As GUID
    Dim objPicture As IPictureDisp
    
    Call CLSIDFromString(StrPtr( _
        GUID_IPICTUREDISP), udtID_IDispatch)
    
    With udtPicInfo
        .lngSize = Len(udtPicInfo)
        .lngType = PICTYPE_BITMAP
        .lnghPic = lnghPic
        .lnghPal = lnghPal
    End With
    
    Call OleCreatePictureIndirect(udtPicInfo, _
        udtID_IDispatch, 0&, objPicture)
    
    Set Create_Picture = objPicture
    
    Set objPicture = Nothing
    
End Function

Starte Das UserForm, es wird das Forum angezeigt und dann ein Bild davon in Zelle C3 eingefügt.
Gruß
Nepumuk

Anzeige
AW: Print Microsoft Web Browser Fenster
08.04.2015 14:56:46
Nicolaus
Ok, vielen Dank!
Habe auch noch nie Userforma benutzt, weshalb das jetzt alles ein bisschen länger dauern wird.
Aber ich versuche es mal und berichte über Erfolg oder Misserfolg :)
Auf jeden Fall schonmal vielen Dank!

AW: Print Microsoft Web Browser Fenster
08.04.2015 15:17:11
Nicolaus
Also, ich sehe, dass es kurzzeitig genau das macht, was ich wollte (schließt VB und zeigt den browser im Fenster an). Dann aber geht er wieder zum VB Code vom Userform und sagt "Compile Error: Variable not defined" - das scheint sich auf "Tabelle1" zu beziehen.
Weißt du, woran das liegen könnte?
Vielen Dank!
Gruß,
Nico

Anzeige
AW: Print Microsoft Web Browser Fenster
08.04.2015 15:22:19
Nicolaus
Bei mir hier ist alles auf englisch, vllt kommt es deshalb mit Sachen wie "Tabelle 1" oder "Fehler beim Erstellen des Bildes" nicht klar :/

AW: Print Microsoft Web Browser Fenster
08.04.2015 15:22:52
Nepumuk
Hallo,
du musst den Namen der Tabelle in welcher das Bild erscheinen soll natürlich anpassen.
With Tabelle1 'Anpassen !!!!!!!!!!!!!!!!!!!!1
    Call .Shapes.AddPicture(strFileName, msoFalse, msoTrue, _
        .Cells(3.3).Left, .Cells(3, 3).Top, -1, -1)
End With

Wobei das der Objektname der Tabelle ist !!!
Gruß
Nepumuk

Anzeige
AW: Print Microsoft Web Browser Fenster
08.04.2015 15:56:30
Nicolaus
Ok, macht Sinn :)
Weil sich der Name des Sheets standing verändern wird (v123123 etc.) habe ich jetzt statt des Namens der Tabelle das ganze jetzt auf Zelle ("A1") bezogen. In A1 wird immer der Name der Tabelle angezeigt.
Userbild
in VB zeigt er jetzt das an und wenn ich dort rausgehe zeigt er auch kein Bild an. Wenn ich aber (ausgetrickst) nur in den normalen Modus gehe, ohne VB zu schließen, zeigt er es an. Siehe Bild.
Tut mir echt leid hier so absolut gar keinen Plan von der Geschichte zu haben (just an analyst trying to do his job :))
Danke!

Anzeige
AW: Print Microsoft Web Browser Fenster
08.04.2015 16:03:49
Nepumuk
Hallo,
das ist ja sowieso die aktive Tabelle. Setz da mal ActiveSheet ein.
Gruß
Nepumuk

AW: Print Microsoft Web Browser Fenster
08.04.2015 16:08:06
Nicolaus
Sehr gut! Es funktioniert!
Vielen vielen Dank!
Jetzt nur noch mit den Buttons etc verlinken und ab gehts :)
Beste Grüße,
Nico

AW: Print Microsoft Web Browser Fenster
08.04.2015 17:04:52
Nicolaus
Ok, also nochmal zurück. Sorry dafür.
Im Moment nimmt er von irgendwas einen Screenshot (irgend eine Größe, irgendwo auf meinem Bildschirm, etc.) und ich kann nicht genau erkennen, an welchen Stellschrauben ich drehen muss, um genau das zu verändern.
Was das finale Outcome sein soll, ist dass ich einen Screenshot nur von dem Browser Ausschnitt (Userform) habe und mir den platzieren kann, wo ich will. Ich möchte quasi auf dem sheet eine Straße eingeben, auf einen button drücken, er öffnet dann google maps mit der adresse, pasted einen screenshot des browser ausschnitts mit google maps auf das sheet und das ganze ist dann fix und fertig zum drucken. :/
Ich weiß, dass ich von dem ursprünglichen Code Sachen verändern muss, aber ich weiß nicht genau was, damit es o.g. so macht, wie ich es will :)))
Danke und Gruß,
Nico

Anzeige
AW: Print Microsoft Web Browser Fenster
08.04.2015 17:26:28
Nepumuk
Hallo,
dann lade mal eine Mappe mit der entsprechenden Tabelle sprich Internetadresse in der richtigen Zelle und irgendein Bild in der richtigen Größe hoch.
Gruß
Nepumuk

AW: Print Microsoft Web Browser Fenster
08.04.2015 17:47:58
Nicolaus
https://www.herber.de/bbs/user/96951.xlsx
Here you go.
Das ganze soll dann so aussehen:
Userbild
Die Homepage (welche sich verändern wird, je nachdem welche adresse ich eintrage) wird in Zelle H1 angezeigt.
Danke für die Mühen!
Beste Grüße,
Nico

Anzeige
AW: Print Microsoft Web Browser Fenster
08.04.2015 19:28:40
Nepumuk
Hallo,
teste mal (den Webbrowser bringe ich aber nicht dazu deine Ansicht zu laden):
https://www.herber.de/bbs/user/96953.xlsm
Gruß
Nepumuk

20 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige