【发布时间】:2014-05-10 15:30:08
【问题描述】:
我正在尝试创建一个将一张或多张图片作为输入的 Excel 宏。然后它将图像作为注释添加到选定的单元格。我已经完成了这么多。
接下来我要做的是获取图片的路径并将其作为超链接插入到单元格中。
例如
图片 - \server\share\test\image.jpg
插入图片作为评论
将图片路径作为文本插入
到目前为止,这是我的代码:
Sub ImageLinkComment()
Dim Pict() As Variant
Dim ImgFileFormat As String
Dim PictCell As Range
Dim lLoop As Long
Dim sShape As Picture
ActiveSheet.Protect False, False, False, False, False
ImgFileFormat = "All Picture Files(*.emf;*.wmf;*.jpg;*.jpeg;*.jfif;*.jpe;*.png;*.bpm;*.gif;*.gfa;*.emz;*.wmz;*.pcz;*.tif;*.tiff;*.cgm;*.eps;*.pct;*.pict;*.wpg;*.pcd;*.pcx;*.cdr;*.fpx;*.mix), *.bmp"
'Note you can load in any nearly file format
Pict = Application.GetOpenFilename(ImgFileFormat, MultiSelect:=True)
If Not IsArray(Pict) Then
Debug.Print "No files selected."
Exit Sub
End If
Set PictCell = Selection.Cells(1)
For lLoop = LBound(Pict) To UBound(Pict)
PictCell.AddComment
PictCell.Comment.Visible = False
PictCell.Comment.Shape.Height = 215
PictCell.Comment.Shape.Width = 195
PictCell.Comment.Shape.Fill.UserPicture Pict(lLoop)
Set PictCell = PictCell.Offset(1)
Next lLoop
End Sub
【问题讨论】: