作者:乔山办公网日期:
返回目录:excel表格制作
如下代码可插入到指定单元抄格。
Range("a1").Select '选中A1单元格
ActiveSheet.Shapes.AddShape(msoShapeRectangle, Range("a1").Left, _
Range("a1").Top, Range("a1").Width, Range("a1").Height).Select
Selection.ShapeRange.Fill.UserPicture picpath '在A1单元格插入图片,大袭小与单元格一样。
VBA是Visual Basic for
Applications的缩写,是内嵌于office软件中的一个开发模块,这个模块提供程序自主开知发,语言基础和VB(Visual
Basic)相似。在Excel的“工道具—宏—编辑器”可以打开,也可按Alt+F11打开
' a列为图片名c列显示图片
Sub insertPic()
Dim i As Integer
Dim FilPath As String
Dim rng As Range
Dim s As String
With Sheets("sheet1")
For i = 3 To .Range("a65536").End(xlUp).Row
FilPath = ThisWorkbook.Path & "\" & "图片档案" & "\" & .Cells(i, 1).Text & ".jpg"
If Dir(FilPath) <> "" Then
.Pictures.Insert(FilPath).Select
Set rng = .Cells(i, 3)
With Selection
.Top = rng.Top + 1
.Left = rng.Left + 1
.Width = rng.Width - 1
.Height = rng.Height - 1
End With
Else
s = s & Chr(10) & .Cells(i, 1).Text
End If
Next
.Cells(3, 1).Select
End With
If s <> "" Then
MsgBox s & Chr(10) & "没有照片!e69da5e6ba90e799bee5baa6e997aee7ad94331"
End If
End Sub
参考一下
怎样的相对应?
单元格格式大小是可以实现的
重点是你说的对应
判断刀号列不为空时,用addpicture函数插入图片即可。记得要遍历所有行。