今又 发表于 2015-8-4 17:30
好的,太感谢了。省了很多时间,明天上午看,如果有问题,会继续请教的,下班啦
Option Explicit
'插入图片
Sub InsertPic()
Dim A(1 To 3), i%, j%, p$, f$
ActiveSheet.Pictures.Delete
A(1) = 5 'InputBox("开始行号:")
A(2) = 124 'InputBox("结束行号:")
A(3) = 1 'InputBox("间隔行数:")
p = ThisWorkbook.Path & "\pic\"
For i = A(1) To A(2) Step A(3)
f = p & Cells(i, 1) & ".jpg"
If Dir(f) <> "" Then
With Cells(i, "I")
ActiveSheet.Shapes.AddPicture Filename:=f, _
LinkToFile:=msoTrue, _
SaveWithDocument:=msoTrue, _
Left:=.Left, _
Top:=.Top, _
Width:=.Width, _
Height:=.Height
End With
End If
Next i
Call SetOnAction
End Sub
'设置单击指定对象时运行的宏的名称
Sub SetOnAction()
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
If shp.Type = 11 Then shp.OnAction = "ActionClick"
Next
End Sub
'单击图片所执行的事情
Sub ActionClick()
Dim n
n = 3 '放大系数
With ActiveSheet.Shapes(Application.Caller)
.ZOrder msoBringToFront
If .Width = Range("i:i").Width Then
.Width = .Width * n: .Height = .Height * n
Else
.Width = .Width / n: .Height = .Height / n
End If
End With
End Sub
你好,老师,我现在要更改序号列和插入图片的列,应该怎么改,如果图片在G列,序号在H列,自己试着改了一下不成功,
谢谢啦
|