|
Sub 画像Jpeg保存()
Dim AcSh As Worksheet, NwBk As Workbook
Dim Obj As Object, Crt As Chart, CrtNm As String
Dim Rgh As Double, Rgw As Double
Dim LT As String, BR As String, 図形右上セル As String
Dim 画像名 As String
Set AcSh = ActiveSheet
Set NwBk = Workbooks.Add
Set Crt = NwBk.Sheets(1).ChartObjects.Add(0, 0, Rgw, Rgh).Chart
CrtNm = Mid(Crt.Name, InStr(1, Crt.Name, " ") + 1)
For Each Obj In AcSh.DrawingObjects.ShapeRange
'グループ化された画像にについては無視。
With Obj
If .Type = msoPicture Then
LT = .TopLeftCell.Address
BR = .BottomRightCell.Address
図形右上セル = AcSh.Range(LT, BR).Rows(1).Cells(AcSh.Range(LT, BR).Rows(1).Cells.Count).Address
If AcSh.Range(図形右上セル).Row <> 1 Then
画像名 = AcSh.Range(図形右上セル).Offset(-1).Value
Else
画像名 = AcSh.Range(図形右上セル).Offset(, 1).Value
End If
Rgh = .Height + 7
Rgw = .Width + 7
'NwBk.Sheets(1).Shapes(CrtNm).Height = Rgh
'NwBk.Sheets(1).Shapes(CrtNm).Width = Rgw
NwBk.Sheets(1).ChartObjects(CrtNm).Height = Rgh
NwBk.Sheets(1).ChartObjects(CrtNm).Width = Rgw
.CopyPicture Format:=xlBitmap
With Crt
.Paste
.ChartArea.Border.LineStyle = 0
.Export CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\" & 画像名 & ".jpg"
DoEvents
End With
NwBk.Sheets(1).ChartObjects(CrtNm).Chart.Shapes(1).Delete
End If
End With
Next
NwBk.Sheets(1).ChartObjects(CrtNm).Delete
NwBk.Close (False)
Set AcSh = Nothing
Set NwBk = Nothing
Set Crt = Nothing
End Sub
|
|