插入的图片在Excel中不可见(仅限大小边框)

时间:2017-11-27 08:32:33

标签: excel vba image

我在excel中找到/写了一个宏,它允许我在单元格中插入一张图片,以便excel自动将图片调整到单元格的大小。

Sub InsertAndSizePhoto()
    Dim sFileName As String
    Dim oShape As Shape
    If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
    Dim myPath As String
    Dim folderPath As String

    folderPath = Application.ActiveWorkbook.Path
    sFileName = Application.GetOpenFilename( _
        FileFilter:="Images (*.gif;*.jpg;*.png), *.gif;*.jpg;*.png", _
        FilterIndex:=1, _
        Title:="Insert Picture", _
        ButtonText:="Insert", _
        MultiSelect:=False)
    If sFileName = "False" Then Exit Sub

    With ActiveCell.MergeArea
        ActiveSheet.Shapes.AddPicture _
            Filename:=sFileName, _
            LinkToFile:=msoFalse, _
            SaveWithDocument:=msoTrue, _
            Left:=.Left, _
            Top:=.Top, _
            Width:=.Width, _
            Height:=.Height
    End With
End Sub

有时会插入并安装多个图片,但它们不可见。单击图片时,只有大小调整窗口/边框变得可见。它们在打印预览中也不可见。当我用纸上的PDF打印文档时,它们是可见的。

当我重新打开工作簿时,图片再次可见。是什么导致这个问题?怎么解决?在选项中,所有对象都是可见的。

sample of picture

1 个答案:

答案 0 :(得分:0)

以下是使用Pictures.Insert:

的示例代码
With ActiveSheet.Pictures.Insert(Filename:=sFileName, LinkToFile:=False, SaveWithDocument:=True)
    .Placement = xlMoveAndSize
    With .ShapeRange
        .Height = ActiveCell.MergeArea.Height
        .Width = ActiveCell.MergeArea.Width
        .Left = ActiveCell.MergeArea.Left
        .Top = ActiveCell.MergeArea.Top
    End With
End With