使用VBA在EXCEL中插入图片自定义函数(网络URL/本地URL)

来源:互联网 发布:天策军爷捏脸数据 编辑:程序博客网 时间:2024/05/21 11:37
Sub InsertPic(ByVal 图片链接 As String, ByVal 插入图片表名 As String, ByVal 插入图片单元格地址 As String)    On Error Resume Next    Dim rng As Range    Set rng = Sheets(插入图片表名).Range(插入图片单元格地址)    With Sheets(插入图片表名).Pictures.Insert(图片链接)        .ShapeRange.LockAspectRatio = msoFalse '取消锁定比例        .Width = rng.Width - 3        .Height = rng.Height - 3        .Top = rng.Top + 1.5        .Left = rng.Left + 1.5        If Err.Number <> 0 Then            .Delete            Err.Clear        End If    End With    Set rng = NothingEnd SubSub InsertPic2(ByVal 图片链接 As String, ByVal 插入图片表名 As String, ByVal 插入图片单元格地址 As String)    On Error Resume Next    Dim rng As Range    Set rng = Sheets(插入图片表名).Range(插入图片单元格地址)    With Sheets(插入图片表名).Shapes.AddShape(msoShapeRectangle, rng.Left + 1.5, rng.Top + 1.5, rng.Width - 3, rng.Height - 3).Select '插入一个矩形框        Selection.ShapeRange.Fill.UserPicture 图片链接 '给框内填充图片        Selection.ShapeRange.Line.Visible = msoFalse '无边框        If Err.Number <> 0 Then            Selection.Delete            Err.Clear        End If    End With    Set rng = NothingEnd SubSub 调用()    Call InsertPic("http://www.baidu.com/img/bd_logo1.png", ActiveSheet.Name, "c1")End Sub

阅读全文
0 0
原创粉丝点击