Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. Public Declare Function URLDownloadToFile Lib "urlmon" Alias _
  2. "URLDownloadToFileA" (ByVal pCaller As Long, _
  3. ByVal szURL As String, _
  4. ByVal szFileName As String, _
  5. ByVal dwReserved As Long, _
  6. ByVal lpfnCB As Long) As Long
  7.  
  8. Public Sub GURoL(url As String, FileName As String)
  9. Dim lngRetVal As Long
  10. lngRetVal = URLDownloadToFile(0, url, FileName, 0, 0)
  11. If lngRetVal <> 0 Then
  12. MsgBox "GURol godo: Can't download from " & url & " to " & FileName
  13. End If
  14. End Sub
  15.  
  16. Sub a()
  17. Dim url_column As Range
  18. Dim image_column As Range
  19. Dim myPicture As Picture 'embedded pic
  20. Dim hasImage_column As Range
  21. Dim hasImage As String
  22. Dim shape As shape
  23. Dim localImagePath As String
  24.  
  25. Dim fromRow As Integer
  26. Dim toRow As Integer
  27.  
  28. fromRow = 4250
  29. toRow = 4259
  30.  
  31. Set url_column = Worksheets(2).Range("I" & fromRow & ":I" & toRow)
  32. Set image_column = Worksheets(2).Range("J" & fromRow & ":J" & toRow)
  33. Set hasImage_column = Worksheets(2).Range("K" & fromRow & ":K" & toRow)
  34.  
  35. Dim i As Long
  36. For i = 1 To url_column.Cells.Count
  37. On Error GoTo NextRow:
  38.  
  39. Debug.Print (url_column.Cells(i).Value & " " & (fromRow + i - 1))
  40.  
  41. hasImage = hasImage_column.Cells(i).Value
  42.  
  43. If hasImage = "1" Then GoTo NextRow
  44.  
  45. localImagePath = "c:\Temp\xls-" & (fromRow + i - 1) & ".png"
  46. Call GURoL(url_column.Cells(i).Value, localImagePath)
  47.  
  48. 'Set myPicture = ActiveSheet.Pictures.Insert(localImagePath)
  49. Set shape = ActiveSheet.Shapes.AddPicture(localImagePath, msoFalse, msoTrue, 0, 0, 100, 100)
  50.  
  51. With shape
  52. .Left = image_column.Cells(i).Left
  53. .Top = image_column.Cells(i).Top
  54. .Height = 50
  55. .Width = 50
  56. image_column.Cells(i).EntireRow.RowHeight = .Height
  57. End With
  58.  
  59. hasImage_column.Cells(i).Value = "1"
  60.  
  61. NextRow:
  62. Resume NextRow2
  63. NextRow2:
  64. Next
  65. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement