Есть ли способ извлечь изображения из гиперссылки и вставить их в документ MS Word с помощью VBA? К сожалению, я нашел несколько VBA-скриптов Excel, которые автоматизируют этот процесс. Один из них:
Sub InstallPictures()
Dim i As Long
Dim v As String
Dim cl As Range
Dim pic As Shape
Dim errors As New Collection
i = 2
Set cl = Cells(i, 15)
Do While Trim(cl.Value) <> vbNullString
v = Trim(cl.Value)
cl.ClearComments
With ActiveSheet.Pictures
On Error GoTo ErrHandler
Set p = .Insert(Trim(v))
On Error GoTo 0
' I added this code to resize & arrange the pictures
' you can remove it if you don't need it
p.TopLeftCell = cl.Offset(0, -1)
p.Top = cl.Offset(0, -1).Top
p.Left = cl.Offset(0, -1).Left
p.Height = Cells(i, 15).Height
p.Width = Cells(1, 15).Width
'''''''''''''''''''''''''''''
End With
NextCell:
i = i + 1
Set cl = Cells(i, 15)
Loop
If errors.Count > 0 Then
MsgBox "There were errors, please review the comments as some files may need to be manually downloaded"
End If
Exit Sub
ErrHandler:
Call ErrorNote(v, cl, errors)
Resume NextCell
End Sub
Private Sub ErrorNote(url$, cl As Range, ByRef errs As Collection)
' Adds an item to the errs collection and flags the offending
' cell with a Comment indicating the error occurred.
On Error Resume Next
errs.Add (url)
With cl
.ClearComments
.AddComment ("Error with URL: " & vbCrLf & url)
End With
End Sub
В идеальном случае диапазон - это выбранный URL, а не весь документ.
Большое спасибо за потраченное время! Это мне очень поможет.