Screenshot of a webpage and saving it
Ju
-
Ju -
Ju -
Hello everyone,
I want to create a macro that seems quite complicated (I am a beginner in VBA) so I am struggling a bit, actually a lot.
I want my macro to open an IE page, take a screenshot of it, save it in a folder naming it based on the time of capture, and repeat the operation every 5 minutes for 1 hour while refreshing my internet page each time.
So far, I know how to open an IE page:
I found a code that saves a screenshot in the workbook folder (thanks to cs_Le Pivert by the way) but I don't really know how to save the name based on the time; maybe change "/monimage" to Now but to make it work:
Could someone please help me out?
Bye and thank you in advance,
Ju
Configuration: Windows 7 / Internet Explorer 8.0
I want to create a macro that seems quite complicated (I am a beginner in VBA) so I am struggling a bit, actually a lot.
I want my macro to open an IE page, take a screenshot of it, save it in a folder naming it based on the time of capture, and repeat the operation every 5 minutes for 1 hour while refreshing my internet page each time.
So far, I know how to open an IE page:
Dim IE As InternetExplorer
Dim nb As Integer
Dim DataType
Set IE = CreateObject("internetExplorer.Application")
IE.Visible = True
IE.navigate "https://www.google.com/"
I found a code that saves a screenshot in the workbook folder (thanks to cs_Le Pivert by the way) but I don't really know how to save the name based on the time; maybe change "/monimage" to Now but to make it work:
Option Explicit
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Private Sub CommandButton1_Click()
Dim monImage As String
Dim Sh As Shape
'Defines the name and storage location of the image
monImage = ActiveWorkbook.Path & "\monimage" & ".jpg"
keybd_event vbKeySnapshot, 1, 0&, 0&
DoEvents
Range("A1").Select
ActiveSheet.Paste
'Retrieves the last shape of the sheet
Set Sh = ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
'Pastes the image into a chart
With ActiveSheet.ChartObjects.Add(0, 0, Sh.Width, Sh.Height).Chart
.Paste
'Saves the chart image in jpg format
.Export monImage, "JPG"
End With
'Deletes the chart and the shape.
With ActiveSheet
.ChartObjects(ActiveSheet.ChartObjects.Count).Delete
.Shapes(ActiveSheet.Shapes.Count).Delete
End With
Application.ScreenUpdating = True
MsgBox "The image is saved in the workbook folder."
End Sub
Could someone please help me out?
Bye and thank you in advance,
Ju
Configuration: Windows 7 / Internet Explorer 8.0