|
链接到对应的图片?- Option Explicit
- Sub cmdStart()
- Dim pic As Object
- Dim strFolderName As String
- Dim strFilePath As String
- Dim i As Long
- Application.ScreenUpdating = False
- With Application.FileDialog(msoFileDialogFolderPicker)
- If .Show = True Then
- strFolderName = .SelectedItems(1) & ""
- End If
- End With
- For i = 1 To ActiveSheet.Range("B65536").End(3).Row
- strFilePath = strFolderName & "" & Cells(i, 2) & ".jpg"
- If Dir(strFilePath, vbDirectory) <> vbNullString Then
- With ActiveSheet.Cells(i, 2) '根据B列文字插入图片,但怎么插入图片后,点击图片就能实现超链接?
- Set pic = ActiveSheet.Shapes.AddPicture(Filename:=strFilePath, LinkToFile:=msoFalse, _
- SaveWithDocument:=msoTrue, Left:=.Left, _
- Top:=.Top, Width:=.Width, Height:=.Height)
- ActiveSheet.Hyperlinks.Add Anchor:=pic, Address:=Cells(i, 2) & ".jpg"
- 'pic.Select
- End With
- End If
- Next i
- Excel.Application.ScreenUpdating = True
- Set pic = Nothing
- End Sub
复制代码 |
|