读书人

Excel技艺批量导入导出图片VBA

发布时间: 2013-01-27 13:55:24 作者: rapoo

Excel技巧,批量导入导出图片VBA
Sub save_pic()For Each p In ActiveSheet.Shapes ph = p.Height pw = p.Width p.ScaleHeight 1, True p.ScaleWidth 1, True pn = p.TopLeftCell.Offset(0, -1).Value Debug.Print pn, ph, pw, p.Name p.Name = pn p.CopyPicture With ActiveSheet.ChartObjects.Add(0, 0, p.Width + 5, p.Height + 5).Chart .Paste .Export "D:\ex\" & p.Name & ".jpg", "JPG" .Parent.Delete End With p.Width = pw p.Height = ph Exit ForNextEnd Sub

?

Sub addpic()For Each Shp In ActiveSheet.Shapes      If Shp.Type = msoPicture Then Shp.Delete  Next  i = 2  Do While Range("A" & i) <> ""  Range("B" & i).Select  Set mypic = ActiveSheet.Pictures.Insert("D:\www\pendant\" & Range("A" & i) & ".jpg")  With mypic  .ShapeRange.LockAspectRatio = msoFalse  .Top = Range("B" & i).Top + 5  .Left = Range("B" & i).Left + 5  .Height = Range("B" & i).Height - 10    .Width = Range("B" & i).Width - 10    .Placement = xlMoveAndSize  End With  i = i + 1  Loop  Set mypic = Nothing  End Sub

?

读书人网 >VBA

热点推荐