在单元格中插入图片的宏会创建一个链接,导致“链接的图像无法显示”#39;错误

时间:2017-03-16 16:03:49

标签: excel image vba excel-vba

我使用以下内容在单元格中插入图像并使用该单元格调整大小。但是,当我将其发送给无法访问该驱动器的人时,它会链接到我的链接图像无法显示错误'。我想打破'此链接并将文档保存在文档中。我已经读过我需要使用形状而不是图像,但我正在努力使这个工作。你能帮我吗?谢谢。

Sub InsertPicture()
 Dim sPicture As String, pic As Picture

 sPicture = Application.GetOpenFilename _
 ("Pictures (*.gif; *.jpg; *.bmp; *.tif), *.gif; *.jpg; *.bmp; *.tif", _
 , "Select Picture to Import")

 If sPicture = "False" Then Exit Sub

 Set pic = ActiveSheet.Pictures.Insert(sPicture)
 With pic
 .ShapeRange.LockAspectRatio = msoFalse
 .Height = ActiveCell.Height
 .Width = ActiveCell.Width
 .Top = ActiveCell.Top
 .Left = ActiveCell.Left
 .Placement = xlMoveAndSize
 End With

 Set pic = Nothing

 End Sub

1 个答案:

答案 0 :(得分:0)

尝试:

Sub InsertPicture()
     Dim sPicture As String

     sPicture = Application.GetOpenFilename _
     ("Pictures (*.gif; *.jpg; *.bmp; *.tif), *.gif; *.jpg; *.bmp; *.tif", _
     , "Select Picture to Import")

     If sPicture = "False" Then Exit Sub

     Dim Rng As Range: Set Rng = ActiveCell


     ActiveSheet.Shapes.AddPicture(sPicture, msoFalse, msoTrue, _
       Rng.Left, Rng.Top, Rng.Width, Rng.Height).Placement = xlMoveAndSize

 End Sub