|
楼主 |
发表于 2020-2-11 22:13
|
显示全部楼层
改为最多连续九列插图 Sub cb4(control As IRibbonControl)
If MsgBox("在当前工作表全选匹配内容(如序列号、证件号、型号之类)所在单元格区域、再单击待插图区域首列任一单元格,把名称一致的图批量导入工作表的连续的一至九列格子中,图的大小位置随格子。注意事项:" & Chr(10) & "1、所有待插图先集中保存在一个文件夹中;2、图须完善命名,同行第二至第九个图命名时,约定在图名称右边依次增加 半角“-2、-3、-4、……、-9”,格式为最常用的 .jpg。" & Chr(10) & "如果不用本功能,请单击“取消”或“X”。", vbOKCancel + vbInformation, "功能说明:") <> vbOK Then Exit Sub
If TypeName(Selection) <> "Range" Then Cells(1).Select
Dim i As Byte, idran As Range, inran As Range, shapepath As String
On Error GoTo errline
i = InputBox("请在下框输录 数字 来确定图插成几列:" & Chr(10) & "1、一列;2、二列;……;9、九列。", "数据设置:", 1)
If i > 9 Or i < 1 Then
MsgBox "设置不可用。", , "微软的提醒:"
Exit Sub
End If
Set idran = Application.InputBox("请全选匹配内容所在单元格区域:", "数据设置2:", , , , , , 8)
Set inran = Application.InputBox("请选择待插图区域首列任一单元格:", "数据设置3:", , , , , , 8)
With Application.FileDialog(FileDialogtype:=msoFileDialogFolderPicker)
.Title = "请“双击”打开各文件夹,最后“双击”或“单击”图所在文件夹后,单击“确定”。"
If .Show = -1 Then
shapepath = .SelectedItems(1)
Else
Exit Sub
End If
End With
shapepath = shapepath & IIf(Right(shapepath, 1) = "\", "", "\")
Dim n As Byte, myran As Range, fulnam As String, ml As Double, mt As Double, mw As Double, mh As Double, mysha As Shape
On Error Resume Next
Application.ScreenUpdating = False
For Each myran In idran
If Not IsEmpty(myran) Then
If i = 1 Then
fulnam = shapepath & myran.Value & ".jpg"
ml = myran.Offset(0, inran.Column - myran.Column).Left
mt = myran.Offset(0, inran.Column - myran.Column).Top
mw = myran.Offset(0, inran.Column - myran.Column).Width
mh = myran.Offset(0, inran.Column - myran.Column).Height
Set mysha = ActiveSheet.Shapes.AddPicture(Filename:=fulnam, LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=ml, Top:=mt, Width:=mw, Height:=mh).Select
Else
fulnam = shapepath & myran.Value & ".jpg"
ml = myran.Offset(0, inran.Column - myran.Column).Left
mt = myran.Offset(0, inran.Column - myran.Column).Top
mw = myran.Offset(0, inran.Column - myran.Column).Width
mh = myran.Offset(0, inran.Column - myran.Column).Height
Set mysha = ActiveSheet.Shapes.AddPicture(Filename:=fulnam, LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=ml, Top:=mt, Width:=mw, Height:=mh).Select
For n = 2 To i
fulnam = shapepath & myran.Value & "-" & n & ".jpg"
ml = myran.Offset(0, inran.Column - myran.Column + n - 1).Left
mt = myran.Offset(0, inran.Column - myran.Column + n - 1).Top
mw = myran.Offset(0, inran.Column - myran.Column + n - 1).Width
mh = myran.Offset(0, inran.Column - myran.Column + n - 1).Height
Set mysha = ActiveSheet.Shapes.AddPicture(Filename:=fulnam, LinkToFile:=msoTrue, SaveWithDocument:=msoTrue, Left:=ml, Top:=mt, Width:=mw, Height:=mh).Select
Next
End If
mysha.Placement = xlMoveAndSize
mysha.Name = Dir(fulnam)
End If
Next
idran.Item(1).Select
Application.ScreenUpdating = True
errline:
End Sub
|
|