khongtu19bk
Thành viên hoạt động
![](/diendan/data/PhoToDanhHieu/gold.gif)
![](/diendan/data/PhoToDanhHieu/gold.gif)
![](/diendan/data/PhoToDanhHieu/gold.gif)
- Tham gia
- 5/12/09
- Bài viết
- 147
- Được thích
- 69
Bài toán của mình là : có một trang web html, phải chụp ảnh lưu thành ảnh dán vào excel.
vì scrollbar phải kéo liên tục, chụp thành nhiều bức ảnh rồi ghép lại cho nên rất mất thời gian.
Mong muốn có thể dùng VBA chụp ảnh.
Mình tìm được đoạn code này trên mạng nhưng chưa điều khiển được thành scrollbar để có thể chụp thành nhiều bức ảnh ghép lại thành cả trang web.
Vậy ai biết xin mách dùm.
code tham khảo.
vì scrollbar phải kéo liên tục, chụp thành nhiều bức ảnh rồi ghép lại cho nên rất mất thời gian.
Mong muốn có thể dùng VBA chụp ảnh.
Mình tìm được đoạn code này trên mạng nhưng chưa điều khiển được thành scrollbar để có thể chụp thành nhiều bức ảnh ghép lại thành cả trang web.
Vậy ai biết xin mách dùm.
code tham khảo.
Mã:
Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As LongLong, ByVal dwExtraInfo As LongPtr)
Private Const VK_SNAPSHOT As Byte = 44
Public Function StoreScreenShotFrom_As(URL_Dest As String, Img_Name As String, Img_Type As String)
Dim IE As Object, IECaption As String
Dim aXL As Object, aWB As Object, aSh As Object, aChO As Object, Img_Path As String
Img_Path = VBA.Environ$("temp") & "\" & Img_Name & "." & Img_Type
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.FullScreen = True
.Navigate URL_Dest
'''Possibilities to wait until the page is loaded
'Do While .Busy Or .readyState <> 4
' DoEvents
'Loop
'''OR
'Sleep 5000
'''OR (custom sub below)
WasteTime 5
'''Take a snapshot
Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
DoEvents
.Quit
End With 'IE
'''Start Excel
Set aXL = CreateObject("Excel.Application")
On Error Resume Next
With aXL
.WindowState = -4143 'xlNormal
.Top = 1
.Left = 1
.Height = .Document.Body.ScrollRectangle.Height '.UsableHeight
.Width = .UsableWidth
.WindowState = -4137 'xlMaximized
On Error GoTo 0
Set aWB = .Workbooks.Add
Set aSh = aWB.Sheets(1)
Set aChO = aSh.ChartObjects.Add(0, 0, .Width, .Height)
End With 'aXL
With aChO
.Activate
.Chart.Paste
With .ShapeRange
.Line.Visible = msoFalse
.Fill.Visible = msoFalse
End With '.ShapeRange
With .Chart
.Export Filename:=Img_Path, Filtername:=Img_Type, Interactive:=False
End With '.Chart
DoEvents
.Delete
End With 'oChrtO
aWB.Close False
DoEvents
aXL.Quit
StoreScreenShotFrom_As = Img_Path
End Function
Private Sub WasteTime(SecondsToWait As Long)
Dim TimeLater As Date
TimeLater = DateAdd("s", SecondsToWait, Now)
Do While Now < TimeLater
DoEvents
Loop
End Sub
Sub test_Prateek_Narendra()
Dim FilePath As String
Dim objMsg As Object
FilePath = StoreScreenShotFrom_As("https://jpnfriend.net", "TestScrenShot", "jpg")
End Sub