在Excel VBA中插入嵌入的图像

时间:2017-08-14 15:41:25

标签: excel vba excel-vba

我有以下用于在Excel中插入图像的代码,但是当我将文件发送给网络外的用户时,他们无法看到图片。有没有办法修改代码,因为它不会链接,而是嵌入图像? 这是代码:

Private Sub Worksheet_Change(ByVal Target As Range)
If (Target.Count > 1) Or (Split(Target.Address, "$")(1) <> "A") Then Exit Sub

Dim c As Range
Dim myPath As String
myPath = "P:\"
Application.ScreenUpdating = False

For Each c In Target.Cells
    If Not Dir(myPath & "*" & c.Text & "*") = "" Then
        InsertPicture myPath & Dir(myPath & "*" & c.Text & "*"), c.Offset(0, 1)
    End If
Next c
Application.ScreenUpdating = True

End Sub


Sub InsertPicture(thePath As String, theRange As Range)

With ThisWorkbook.ActiveSheet.Pictures.Insert(thePath)
    With .ShapeRange
    .LockAspectRatio = msoTrue
    .Width = theRange.Width
    .Height = theRange.Height
End With
    .Left = theRange.Left
    .Top = theRange.Top
    .Placement = 1
    .PrintObject = True
End With

End Sub

谢谢!

0 个答案:

没有答案