Live-Forum - Die aktuellen Beiträge
Datum
Titel
23.04.2024 14:59:21
23.04.2024 14:47:39
23.04.2024 14:23:45
Anzeige
Archiv - Navigation
1488to1492
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

Website + Screenshot + img speichern

Website + Screenshot + img speichern
24.04.2016 20:16:14
nito-o
Hallo!
Ich möchte gerne ein Makro bauen, welches für mich eine Website aufruft (z.B. Google.de). Im Anschluss soll ein Screenshot erstellt werden und dieser in einem hinterlegten Ordner als img gespeichert werden.
Ich steh noch recht am Anfang und bin etwas überfragt bzgl. dem Screenshot (vllt mit Sendkeys machbar?):
Hiermit rufe ich derzeit die Website auf:

Sub Website()
Shell "C:\Program Files\Mozilla Firefox\firefox.exe http:// _
www.google.de/"
End Sub

7
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Website + Screenshot + img speichern
25.04.2016 10:31:19
nito-o
Danke für deine Antwort Nepumuk.
An sich funktioniert das Makro so wie ich es möchte, allerdings mit einem entscheidenden Schwachpunkt. Es überschreibt die BMP-Dateien.
Mein Ziel ist es, in Excel Website zu hinterlgen z.B. A1:A10. Diese sollen einzeln angesteuert werden, ein Screenshot erstellt und gespeichert werden. Am Ende möchte ich im o.g. Fall 10 Screenshots haben.
Ich hab es soweit angepasst das ich einzelne Dateien als Screenshot bekomme allerdings immer mit dem Inhalt der zuletzt aufgerufenen Seite bzw Screenshot.
Option Explicit
Private Declare Sub Sleep Lib "kernel32.dll" ( _
ByVal dwMilliseconds As Long)
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" ( _
ByRef PicDesc As PicBmp, _
ByRef RefIID As GUID, _
ByVal fPictureOwnsHandle As Long, _
ByRef IPic As IPicture) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32.dll" ( _
ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32.dll" ( _
ByVal hdc As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32.dll" ( _
ByVal hdc As Long, _
ByVal hObject As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32.dll" ( _
ByVal hdc As Long, _
ByVal iCapabilitiy As Long) As Long
Private Declare Function GetSystemPaletteEntries Lib "gdi32.dll" ( _
ByVal hdc As Long, _
ByVal wStartIndex As Long, _
ByVal wNumEntries As Long, _
ByRef lpPaletteEntries As PALETTEENTRY) As Long
Private Declare Function CreatePalette Lib "gdi32.dll" ( _
ByRef lpLogPalette As LOGPALETTE) As Long
Private Declare Function SelectPalette Lib "gdi32.dll" ( _
ByVal hdc As Long, _
ByVal hPalette As Long, _
ByVal bForceBackground As Long) As Long
Private Declare Function RealizePalette Lib "gdi32.dll" ( _
ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32.dll" ( _
ByVal hDestDC As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal hSrcDC As Long, _
ByVal xSrc As Long, _
ByVal ySrc As Long, _
ByVal dwRop As Long) As Long
Private Declare Function DeleteDC Lib "gdi32.dll" ( _
ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32.dll" ( _
ByVal hWnd As Long) As Long
Private Declare Function GetWindowRect Lib "user32.dll" ( _
ByVal hWnd As Long, _
ByRef lpRect As RECT) As Long
Private Declare Function GetSystemMetrics Lib "user32.dll" ( _
ByVal nIndex As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32.dll" () As Long
Private Const SM_CXSCREEN = 0&
Private Const SM_CYSCREEN = 1&
Private Const RC_PALETTE As Long = &H100
Private Const SIZEPALETTE As Long = 104
Private Const RASTERCAPS As Long = 38
Private 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(7) As Byte
End Type
Private Type PicBmp
Size As Long
Type As Long
hBmp As Long
hPal As Long
Reserved As Long
End Type
Sub Website()
Dim i As Integer
Dim d As String
For i = 3 To 4
d = Cells(i, 1)
Shell "C:\Program Files (x86)\Mozilla Firefox\firefox.exe " & d & ""
Sleep 3000 '3 sekunden
stdole.SavePicture hDCToPicture(GetDC(0&), 0&, 0&, _
GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)), _
"\\SW-FRATHC-FIL01\USERS-DE$\T5000188\Desktop\tt\Screenshot " & i & ".bmp" 'anpassen !!! _
Next i
End Sub
Private Function CreateBitmapPicture(ByVal hBmp As Long, ByVal hPal As Long) As Object
Dim Pic As PicBmp, IPic As IPicture, IID_IDispatch As GUID
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
With Pic
.Size = Len(Pic)
.Type = 1
.hBmp = hBmp
.hPal = hPal
End With
Call OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
Set CreateBitmapPicture = IPic
End Function
Private Function hDCToPicture(ByVal hDCSrc As Long, ByVal LeftSrc As Long, _
ByVal TopSrc As Long, ByVal WidthSrc As Long, ByVal HeightSrc As Long) As Object
Dim hDCMemory As Long, hBmp As Long, hBmpPrev As Long
Dim hPal As Long, hPalPrev As Long, RasterCapsScrn As Long, HasPaletteScrn As Long
Dim PaletteSizeScrn As Long, LogPal As LOGPALETTE
hDCMemory = CreateCompatibleDC(hDCSrc)
hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
hBmpPrev = SelectObject(hDCMemory, hBmp)
RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS)
HasPaletteScrn = RasterCapsScrn And RC_PALETTE
PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE)
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
LogPal.palVersion = &H300
LogPal.palNumEntries = 256
Call GetSystemPaletteEntries(hDCSrc, 0, 256, LogPal.palPalEntry(0))
hPal = CreatePalette(LogPal)
hPalPrev = SelectPalette(hDCMemory, hPal, 0)
Call RealizePalette(hDCMemory)
End If
Call BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, LeftSrc, TopSrc, 13369376)
hBmp = SelectObject(hDCMemory, hBmpPrev)
If HasPaletteScrn And (PaletteSizeScrn = 256) Then
hPal = SelectPalette(hDCMemory, hPalPrev, 0)
End If
Call DeleteDC(hDCMemory)
Set hDCToPicture = CreateBitmapPicture(hBmp, hPal)
End Function

Anzeige
AW: Website + Screenshot + img speichern
25.04.2016 12:15:01
Nepumuk
Hallo,
ich kann das nicht testen denn ich arbeite mit dem "normalen" Internetexplorer und wenn ich das mit dem nachvollziehe dann klappt das einwandfrei.
Ich lass die Frage mal offen.
Gruß
Nepumuk

AW: Website + Screenshot + img speichern
25.04.2016 12:18:50
nito-o
Frag mich nicht wie, aber ich habs hinbekommen :D
Jetzt wäre es natürlich noch cool, wenn die BMP Dateien im Ordner per Makro in IMG, PNG oder zusammengefügt als PDF gespeichert / umgewandelt werden können.

AW: Website + Screenshot + img speichern
25.04.2016 16:08:41
Nepumuk
Hallo,
füge die einzelnen Bilde in Word ein und exportiere das dann als PDF. Der Makrorekorder sollte dir dabei helfen das Programm zu entwickeln.
Gruß
Nepumuk

Anzeige
AW: Website + Screenshot + img speichern
26.04.2016 12:33:42
nito-o
Hi,
habs gelöst indem ich die Bitmaps in Excel lade und diese dann zusammengefügt in einem PDF speichere.
Gibt es auch eine Möglichkeit z.B. mit Margin einen Screenshotbereich auszuwählen anstatt den gesamten Bildschirm?

AW: Website + Screenshot + img speichern
26.04.2016 12:57:51
Nepumuk
Hallo,
in dieser Zeile:
hDCToPicture(GetDC(0&), 0&, 0&, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)),
wird die Abmessung des Bildes bestimmt. Teste einfach ein bisschen mit verschiedenen Werten.
Gruß
Nepumuk

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige