次のVBAコードを使用して、ある範囲のセルをjpegに指定したフォルダにエクスポートできます。 1つのワークブック内のすべてのワークシートをループさせたいと思います。範囲をイメージとしてエクスポートするときにループするワークシート
すべての開いているブックからこのコードをループするのに役立つ必要があります。 Dim WSをワークシートとして設定し、Ifステートメントを設定し、次のコードを挿入してifステートメントを終了し、最後に実際にループするように次のWSを配置します。私の問題は、私がif文を結合しようとすると、91エラーが発生するということです。ThisWorkbook.Sheets In EachWorkbook.Sheets If Not WS.Name = "Sheet2"次に、私のコードを以下に示します。
次のコードは、一度に1つのワークシートで機能します。
Sub ExportAsImage()
Dim objPic As Shape
Dim objChart As Chart
Dim i As Integer
Dim intCount As Integer
'copy the range as an image
Call ActiveSheet.Range("A1:F2").CopyPicture(xlScreen, xlPicture)
'remove all previous shapes in the ActiveSheet
intCount = ActiveSheet.Shapes.Count
For i = 1 To intCount
ActiveSheet.Shapes.Item(1).Delete
Next i
'create an empty chart in the ActiveSheet
ActiveSheet.Shapes.AddChart
'select the shape in the ActiveSheet
ActiveSheet.Shapes.Item(1).Select
ActiveSheet.Shapes.Item(1).Width = Range("A1:F2").Width
ActiveSheet.Shapes.Item(1).Height = Range("A1:F2").Height
Set objChart = ActiveChart
'clear the chart
objChart.ChartArea.ClearContents
'paste the range into the chart
objChart.Paste
'save the chart as a JPEG
objChart.Export ("C:\Users\------\Desktop\Test\" & Range("B2").Value & ".jpg")
'remove all shapes in the ActiveSheet
intCount = ActiveSheet.Shapes.Count
For i = 1 To intCount
ActiveSheet.Shapes.Item(1).Delete
Next i
End Sub
コードをすべて編集するように編集してください。 – SJR