|
本帖最后由 shawlay 于 2017-8-8 12:14 编辑
代码如下:我想实现将sheet中的表格保存为图片导出, .Chart.Paste ‘在导出第4张图片时提示1004错误,前面导出3张图片都正常,
若有其它方法实现,请各位大神不吝赐教。
Private Sub CommandButton1_Click()
Dim Sareas As String, FileNames As String
Dim Newshape As Shape
For i = 1 To 5
If i < 5 Then
Select Case i
Case 1
Sareas = "b1:f11"
FileNames = "\A1.jpg"
Case 2
Sareas = "b13:f23"
FileNames = "\A2.jpg"
Case 3
Sareas = "b25:f35"
FileNames = "\A3.jpg"
Case 4
Sareas = "b37:f47"
FileNames = "\A4.jpg"
Case 5
Sareas = "b49:f59"
FileNames = "\A5.jpg"
End Select
Range(Sareas).Select '选定截图区域
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
ActiveSheet.Paste
Set Newshape = ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
With ActiveSheet.ChartObjects.Add(1, 1, 1, 1)
.Width = Newshape.Width
.Height = Newshape.Height
Newshape.Copy
.Chart.Paste ‘在导出第四张表格时提示1004错误
.Chart.Export ActiveWorkbook.Path & FileNames
.Delete
End With
Newshape.Delete
End If
Next
End Sub
|
|