我有VBA代码,它接受图像网址并发布图像(如果它存在于共享驱动器中)。当我尝试将带有图像的excel文件发送给无法访问共享驱动器的人时,他们无法查看图像。有没有解决方法,所以我可以发送给任何人,他们可以查看图像?
答案 0 :(得分:0)
如果某人没有权限查看驱动器上的图像,则可以访问图像。不过,您可以将它们全部加载到Excel中,然后将Excel文件发送给您的同事。
列出要发送的所有图像(在A列中),然后运行下面的脚本。
Sub InsertPics()
Dim fPath As String, fName As String
Dim r As Range, rng As Range
Application.ScreenUpdating = False
fPath = "C:\Users\Public\Pictures\Sample Pictures\"
Set rng = Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
i = 1
For Each r In rng
fName = Dir(fPath)
Do While fName <> ""
If fName = r.Value Then
With ActiveSheet.Pictures.Insert(fPath & fName)
.ShapeRange.LockAspectRatio = msoTrue
Set px = .ShapeRange
If .ShapeRange.Width > Rows(i).Columns(2).Width Then .ShapeRange.Width = Columns(2).Width
With Cells(i, 2)
px.Top = .Top
px.Left = .Left
.RowHeight = px.Height
End With
End With
End If
fName = Dir
Loop
i = i + 1
Next r
Application.ScreenUpdating = True
End Sub
' Note: you need the file extension, such as ',jpg', or whatever you are using, so you can match on that.