VBA EXCEL按指定内容批量插图

时间:2012-11-06 11:06:27
【文件属性】:

文件名称:VBA EXCEL按指定内容批量插图

文件大小:11KB

文件格式:RAR

更新时间:2012-11-06 11:06:27

批量插图

Sub 按列批量插图() '按指定列的内容插入同名图片对应到右边列,图片大小自动适应单元格大小' On Error GoTo aa a = ActiveCell.Column '活动的列' b = a + 1 '活动列的右边一列' D = ActiveSheet.Cells(65536, a).End(xlUp).Row '最后一行 '跳出选择文件夹对话框 Set fd = Application.FileDialog(msoFileDialogFolderPicker) With fd If .Show = -1 Then t = .SelectedItems(1) End If End With For i = 1 To D n = Cells(i, a) '指定单元格的内容为n If n = "" Then GoTo aa '空格时跳到最后 Set fs = Application.FileSearch '设置模糊搜索文件夹 With fs .LookIn = t '路径为T .Filename = n " *.jpg" '文件名为n或者n+?(字数超过n的也以n为准做搜索) If .Execute > 0 Then '开始搜索 For J = 1 To .FoundFiles.Count ActiveSheet.Pictures.Insert(.FoundFiles(J)).Select '符合条件的做插入 Selection.Top = Cells(i, b).Top '设置图片大小 Selection.Left = Cells(i, b).Left Selection.Width = Cells(i, b).Width Selection.Height = Cells(i, b).Height Next J End If End With aa: Next For Each c In ActiveSheet.Pictures c.Height = c.TopLeftCell.MergeArea.Cells.Height ' 图片高度=合并后单元格高 Next End Sub


【文件预览】:
智能按列批量插图.xls

网友评论