VBA将图片插入表格的特定列

时间:2018-10-02 00:18:37

标签: excel vba excel-vba

我有一个用于在活动单元格中插入图片的代码,但我想不出一种方法来修改它以仅在D列单元格而不是活动单元格中插入图片。

Sub InsertPictureInActiveCell()
Dim strFile As String
Dim rng As Range
Dim sh As Shape
Const cFile As String = "Image Files(*.bmp;*.jpg;*.jpeg;*.png),"
strFile = Application.GetOpenFilename(fileFilter:=cFile, Title:=Es)
If strFile = "False" Then
Else
    Set rng = ActiveCell
    Set rng = rng.MergeArea
    With rng
        Set sh = ActiveSheet.Shapes.AddPicture(Filename:=strFile, 
        linkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=.Left, 
        Top:=.Top, Width:=.Width, Height:=.Height)
        sh.LockAspectRatio = msoFalse
        sh.Placement = xlMoveAndSize
        End With
        Set sh = Nothing
        Set rng = Nothing

  End If
 End Sub

我还是VBA的新手。如果有人可以帮助我解决这种情况,我将感到非常高兴。

0 个答案:

没有答案