|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub TEST1()
Dim ar(), br, i&, j&, r&, pic As Picture, dWidth#, dHeight#
Dim strFileName As String, strPath As String, strSavePath$
strPath = ThisWorkbook.Path & "\1原图片\"
strSavePath = ThisWorkbook.Path & "\2新图片\"
strFileName = Dir(strPath & "*.jpeg")
Do Until strFileName = ""
r = r + 1
ReDim Preserve ar(1 To 2, 1 To r)
ar(1, r) = strPath & strFileName
ar(2, r) = strSavePath & strFileName
strFileName = Dir
Loop
If r = 0 Then MsgBox "没有图片,请检查!": Exit Sub
If Dir(strSavePath, vbDirectory) = "" Then MkDir strSavePath
For j = 1 To UBound(ar, 2)
br = GetPic(ar(1, j))
Set pic = ActiveSheet.Pictures.Insert(ar(1, j))
With pic
.ShapeRange.LockAspectRatio = msoTrue
.Width = br(1) * 0.75
.ShapeRange.PictureFormat.CropTop = 100
dWidth = .Width
dHeight = .Height
.Cut
End With
With ActiveSheet.ChartObjects.Add(0, 0, dWidth, dHeight).Chart
.Parent.Select
.Paste
With .Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 10, 200, 35)
With .TextFrame2.TextRange
.Font.Size = 18
.Characters.Text = "自己需要加入的文字"
End With
.Select
With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = vbYellow
.Transparency = 0
.Solid
End With
End With
.Export ar(2, j)
.Parent.Delete
End With
Next j
Beep
End Sub
Function GetPic(ByVal strFileName$) As Long()
Dim ar&(1)
With CreateObject("WIA.ImageFile")
.LoadFile strFileName
ar(0) = .Height: ar(1) = .Width
End With
GetPic = ar
End Function
|
|