Excel中2010版进行引用可变图像的操作技巧
相关话题
在Excel插入一张图片,这是很容易的事情。如果要根据内容的变化来引用图片,就不太好实现啦。今天,小编就教大家在Excel中2010版进行引用可变图像的操作技巧。
Excel中2010版进行引用可变图像的操作步骤
创建实例环境:第一,Excel之可变图片文件夹中,创建一个名叫“头像”的文件夹(用来存放头像图片),创建一个名叫“Excel之可变图片”的excel工作簿;第二,头像文件夹中,存放实例头像图片,“Excel之可变图片”excel工作簿,创建“档案汇总”和“档案查询”工作表;




链接数据库,插入“图像框”和编辑事件代码:第一,以“姓名”为查询对象引用数据,使用“=VLOOKUP($B$3,档案汇总!$A:$R,"该数据在档案汇总的列标",FALSE)”引用“档案汇总”表的数据;第二,在“控件工具箱”点击“图像”控件,在照片单元格添加一个“图片框”用来存放可变图片;第三,右击“图片框”——“查看代码”,选择“worksheet”和“change”事件,录入代码:
Private Sub Worksheet_Change(ByVal Target As Range)
If Dir(ThisWorkbook.Path & "头像" & Cells(3, 2).Value & ".jpg") <> "" Then
Image1.Picture = LoadPicture(ThisWorkbook.Path & "头像" & Cells(3, 2).Value & ".jpg")
Else
Image1.Picture = LoadPicture(ThisWorkbook.Path & "头像" & "空" & ".jpg")
End If
End Sub
保存关闭代码编辑窗口,回到档案查询表退出“图像”设计模式;






在“姓名”值单元格,输入要查找的姓名,查看验证搜索结果。

