做个通用的
Sub 导出所有单元格内容为图片()
Dim i&, Myr&, Arr
Dim d, k, t
filename = Application.GetOpenFilename("Excel 文件 (*.xls*),*.xls*", , "请选择作表!", , 0)
If filename = False Then Exit Sub
Set sjwk = Workbooks.Open(filename) '要分表的数据所在表
shname = sjwk.ActiveSheet.Name
sjwk.Sheets(shname).Activate
Set rng1 = Application.InputBox("请选择工作表完整区域,不要选择整列整行,只选择绝对区域", "选取提示", , , , , , 8)
If rng1 Is Nothing Then MsgBox "您没有选择区域": Exit Sub
On Error Resume Next
myPath = sjwk.path
With sjwk.ActiveSheet
Arr = rng1
For k = 1 To UBound(Arr)
For y = 1 To UBound(Arr, 2)
On Error Resume Next
.Cells(k, y).CopyPicture
Set CHT = ActiveSheet.ChartObjects.add(0, 0, Cells(k, y).Width, Cells(k, y).Height).Chart
With CHT
.Paste
If .Cells(k, y).Value <> "" Then
.Export sjwk.path & "\" & Cells(k, y).Value & i & y & ".JPG"
Else
.Export sjwk.path & "\" & Cells(k, y).Address & i & y & ".JPG"
End If
.Parent.Delete
End With
Next y
Next k
Set CHT = Nothing
End With
End Sub
|