|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub test0()
Dim ar, br, cr, i&, j&, f, strFileName$, strPath$, wks As Worksheet, strExtName$, dic As Object
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set dic = CreateObject("Scripting.Dictionary")
strPath = ThisWorkbook.Path & "\照片\"
With CreateObject("VBScript.RegExp")
.Pattern = "jpg|jpep|png|gif|bmp|gif"
.IgnoreCase = True
For Each f In CreateObject("Scripting.FileSystemObject").GetFolder(strPath).Files
strExtName = Mid(f.Name, InStrRev(f.Name, ".") + 1)
strFileName = Left(f.Name, InStrRev(f.Name, ".") - 1)
If .test(strExtName) Then
dic(strFileName) = f.Path
End If
Next
End With
strPath = ThisWorkbook.Path & "\"
br = [{9,6;5,6;5,12;6,6;3,3;3,9;3,12;4,6;6,12}]
cr = Array(1, 2, 3, 4, 5, 6, 9, 11, 12)
ar = [A1].CurrentRegion.Value
Set wks = Worksheets("附表1 (2)")
For i = 2 To UBound(ar)
wks.Copy
With ActiveWorkbook
strFileName = strPath & ar(i, 1)
With .Worksheets(1)
For j = 1 To UBound(br)
.Cells(br(j, 1), br(j, 2)).Value = ar(i, cr(j - 1))
Next j
If dic.exists(ar(i, 1)) Then
.Cells(3, 15).Select
With .Pictures.Insert(dic(ar(i, 1)))
.ShapeRange.LockAspectRatio = msoTrue
.Left = Selection.Left + 2
.Top = Selection.Top + 2
.Height = Selection.Height - 4
End With
End If
End With
.SaveAs strFileName
.Close
End With
Next i
Set wks = Nothing
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Beep
End Sub
|
评分
-
1
查看全部评分
-
|