VBA,碰到讀圖片和寫圖片:
從工作表中導出圖片
Sub Macro01() '從工作表中保存圖片
Application.ScreenUpdating = False
Dim pth, shp, n pth = ThisWorkbook.Path & "\導出圖片\"
For Each shp In ActiveSheet.Shapes If shp.Type = 13 Then n = n + 1 shp.Copy With ActiveSheet.ChartObjects.Add(0, 0, shp.Width, shp.Height).Chart .Parent.Select .Paste .Export pth & shp.TopLeftCell.Offset(0, -1) & ".jpg" .Parent.Delete End With
End If
Next Application.ScreenUpdating = True
End Sub
從文件夾讀取圖片
Sub Macro02() '從文件夾中讀寫圖片
Dim fso, shp, j, rng, str1, w, y Set fso = CreateObject("Scripting.FileSystemObject") Application.ScreenUpdating = False
For Each shp In ActiveSheet.Shapes If shp.Type = 11 Then shp.Delete Next shp For j = 5 To 70 Cells(j, 6).Select Set rng = Selection str1 = ThisWorkbook.Path & "\導出圖片\" & Cells(j, 6) & ".jpg"
If fso.FileExists(str1) Then ActiveSheet.Pictures.Insert(str1).Select With Selection .Top = rng.Offset(0, 1).Top .Left = rng.Offset(0, 1).Left .Height = rng.Offset(0, 1).Height .Width = rng.Offset(0, 1).Left - rng.Left - 2
End With
End If
Next j Application.ScreenUpdating = True
End Sub
刪除工作表的圖片
Sub Macro04() '刪除工作表中的圖片
Application.ScreenUpdating = False
Dim oSP As Shape For Each oSP In ActiveSheet.Shapes If oSP.Type = 11 Then oSP.Delete End If
Next Application.ScreenUpdating = True
End Sub
作者:
薛定諤的ハチ公
申明:本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。