我想插入图片的同时,给图片赋值上超链接。这个要怎么写
Sub LoadImage()
Dim HLK As Hyperlink, Rng As Range
Dim i As Integer
For i = 1 To Sheets.Count
For Each HLK In Sheets(i).Hyperlinks '循环活动工作表中的各个超链接
If UCase(HLK.Address) Like "*.JPG" Or UCase(HLK.Address) Like "*.JPEG" Or UCase(HLK.Address) Like "*.PNG" Or UCase(HLK.Address) Like "*.GIF" Then '如果链接的位置是jpg或gif图片(此处仅针对此两种图片类型,更多类型可以通过建立数组或字典或正则来判断)
Set Rng = HLK.Range.Offset(0, 0) '设定插入目标图片的位置
With Sheets(i).Pictures.Insert(HLK.Address) '插入链接地址中的图片
On Error Resume Next
If .Height / .Width > Rng.Height / Rng.Width Then '判断图片纵横比与单元格纵横比的比值以确定针对单元格缩放的比例
.Top = Rng.Top
.Left = Rng.Left + (Rng.Width - .Width * Rng.Height / .Height) / 2
.Width = .Width * Rng.Height / .Height
.Height = Rng.Height
.Placement = xlMoveAndSize
//我想给图片加上超链接,这一段要怎么写
.Pictures.Insert(HLK.Range.Value).Select
.Hyperlinks.Add Anchor:=Selection.ShapeRange, Address:=HLK.Range.Value
//我想给图片加上超链接
Else
.Left = Rng.Left
.Top = Rng.Top + (Rng.Height - .Height * Rng.Width / .Width) / 2
.Height = .Height * Rng.Width / .Width
.Width = Rng.Width
.Placement = xlMoveAndSize
//我想给图片加上超链接,这一段要怎么写
.Pictures.Insert(HLK.Range.Value).Select
.Hyperlinks.Add Anchor:=Selection.ShapeRange, Address:=HLK.Range.Value
//我想给图片加上超链接
End If
End With
HLK.Range.Value = "" '删除单元格的图片链接
End If
Next
Next i
End Sub
Sub LoadImage()
Dim HLK As Hyperlink, Rng As Range
Dim i As Integer
For i = 1 To Sheets.Count
For Each HLK In Sheets(i).Hyperlinks '循环活动工作表中的各个超链接
If UCase(HLK.Address) Like "*.JPG" Or UCase(HLK.Address) Like "*.JPEG" Or UCase(HLK.Address) Like "*.PNG" Or UCase(HLK.Address) Like "*.GIF" Then '如果链接的位置是jpg或gif图片(此处仅针对此两种图片类型,更多类型可以通过建立数组或字典或正则来判断)
Set Rng = HLK.Range.Offset(0, 0) '设定插入目标图片的位置
With Sheets(i).Pictures.Insert(HLK.Address) '插入链接地址中的图片
On Error Resume Next
If .Height / .Width > Rng.Height / Rng.Width Then '判断图片纵横比与单元格纵横比的比值以确定针对单元格缩放的比例
.Top = Rng.Top
.Left = Rng.Left + (Rng.Width - .Width * Rng.Height / .Height) / 2
.Width = .Width * Rng.Height / .Height
.Height = Rng.Height
.Placement = xlMoveAndSize
//我想给图片加上超链接,这一段要怎么写
.Pictures.Insert(HLK.Range.Value).Select
.Hyperlinks.Add Anchor:=Selection.ShapeRange, Address:=HLK.Range.Value
//我想给图片加上超链接
Else
.Left = Rng.Left
.Top = Rng.Top + (Rng.Height - .Height * Rng.Width / .Width) / 2
.Height = .Height * Rng.Width / .Width
.Width = Rng.Width
.Placement = xlMoveAndSize
//我想给图片加上超链接,这一段要怎么写
.Pictures.Insert(HLK.Range.Value).Select
.Hyperlinks.Add Anchor:=Selection.ShapeRange, Address:=HLK.Range.Value
//我想给图片加上超链接
End If
End With
HLK.Range.Value = "" '删除单元格的图片链接
End If
Next
Next i
End Sub