【VBA】单元格插入图片,单元格删除图片
2024-08-28 23:21:42
封装函数:
Sub 插入产品形象(strRange As String, datebaseTu As String)
Dim strJpg As String
strJpg = datebaseTu '... .jpg
If Dir(strJpg, vbDirectory) <> "" Then
ActiveSheet.Pictures.Insert(strJpg).Select
Dim cT As Single
Dim cL As Single
Dim cW As Single
Dim cH As Single
Dim w As Single
Dim h As Single cW = Range(strRange).Width
cH = Range(strRange).Height
cT = Range(strRange).Top
cL = Range(strRange).Left w = Selection.Width
h = Selection.Height If w / cW > h / cH Then
Selection.Left = cL + 5
Selection.Width = cW - 5 - 5 '单元格宽度单边-5 不变形
Selection.Top = cT + cH / 2 - Selection.Height / 2 '高度居中
Else
Selection.Top = cT + 5
Selection.Height = cH - 5 - 5 '单元格高度单边-5 不变形
Selection.Left = cL + cW / 2 - Selection.Width / 2 '宽度居中
End If
Selection.Placement = xlMoveAndSize
Selection.PrintObject = msoTrue
End If
End Sub
Sub 删除图片(列号 As Integer, 行号 As Integer)
Dim shp As Shape, i As Integer
Dim s As String
With ActiveSheet
For i = .Shapes.Count To 1 Step -1
On Error Resume Next
Set shp = .Shapes(i)
If shp.TopLeftCell.Column = 列号 And shp.TopLeftCell.Row = 行号 Then
shp.Delete
End If
Next
End With
End Sub
最新文章
- SQL-日期函数
- 基于Enterprise Library的Winform开发框架实现支持国产达梦数据库的扩展操作
- 【BZOJ】3039: 玉蟾宫(DP/单调栈)
- 分布式架构高可用架构篇_08_MyCat在MySQL主从复制基础上实现读写分离
- JS中注意原型链的“指向”
- win7 Sendto修改
- hdoj 4738 Caocao&#39;s Bridges【双连通分量求桥】
- 链表list容器中通过splice合并链表与merge的不同,及需要注意的问题
- chrome误删书签恢复。
- Android OpenGL ES 应用(二) 纹理
- ASP.NET开发,简化与封装
- js如何判断是否在iframe中
- 从理解开始 谈谈px rem 和 em 的区别与联系
- JMeter-自动生成测试报告
- Hive:子查询
- 0x00-Kali Linux 系列入门篇
- day_41_mysql
- 全栈开发工程师微信小程序 - 上
- Jenkins&#160;利用HTML&#160;Publisher&#160;plugin实现HTML文档报告展示
- Html5 和 CSS的简单应用