在excel表中输入编号自动生成对应的图片,已有对应的编号和图片列表。详情见下图
发布网友
发布时间:2022-04-30 07:59
我来回答
共2个回答
热心网友
时间:2023-10-21 12:48
刚有现成的代码啊
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Column = 1 And Target.Row > 1 Then
Dim fso, shp As Object
Dim rgTL As Range
Dim pname As String
pname = "d:\pic\" & Range("A" & Target.Row).Value & ".jpg"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(pname) Then
For Each shp In ActiveSheet.Shapes
Set rgTL = shp.TopLeftCell
If rgTL.Row = Target.Row Then shp.Delete
Next
Set rgTL = Range("C" & Target.Row)
Set shp = ActiveSheet.Pictures.Insert(pname)
shp.ShapeRange.Height = rgTL.Height
shp.Left = (rgTL.Width - shp.Width) / 2 + rgTL.Left
shp.Top = (rgTL.Height - shp.Height) / 2 + rgTL.Top
Else
MsgBox "不存在此名称的图片!"
GoTo e
End If
End If
e:
Set fso = Nothing
End Sub
热心网友
时间:2023-10-21 12:49
超链接可以运用得到,但是会跳转到图片的页面
热心网友
时间:2023-10-21 12:48
刚有现成的代码啊
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Column = 1 And Target.Row > 1 Then
Dim fso, shp As Object
Dim rgTL As Range
Dim pname As String
pname = "d:\pic\" & Range("A" & Target.Row).Value & ".jpg"
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(pname) Then
For Each shp In ActiveSheet.Shapes
Set rgTL = shp.TopLeftCell
If rgTL.Row = Target.Row Then shp.Delete
Next
Set rgTL = Range("C" & Target.Row)
Set shp = ActiveSheet.Pictures.Insert(pname)
shp.ShapeRange.Height = rgTL.Height
shp.Left = (rgTL.Width - shp.Width) / 2 + rgTL.Left
shp.Top = (rgTL.Height - shp.Height) / 2 + rgTL.Top
Else
MsgBox "不存在此名称的图片!"
GoTo e
End If
End If
e:
Set fso = Nothing
End Sub
热心网友
时间:2023-10-21 12:49
超链接可以运用得到,但是会跳转到图片的页面