将Excel工作簿中的图表批量导出成图片文件

  • A+
所属分类:VBA编程

代码的作用是将工作簿中的图片批量导出成JPG文件,因为文件名暂时有错误,也懒得去修改了,所幸就修改成序号吧;

在导出的时候,会让选择存放图片的路径,随意选择一个就可以了;

Sub 导出图表()    
Dim ChartCount As Integer, ActiveChart As Integer, ChartName As String     With ActiveSheet.ChartObjects '引用所有图表         
ChartCount = .Count '记录个数         
If ChartCount <= 1 Then Exit Sub '如果小于等于1 则退出程序         
Dim Fd As Object, PathStr As String, i As Integer         
Set Fd = Application.FileDialog(msoFileDialogFolderPicker)         '打开选择文件的对话框        
 With Fd  '如果选择了目录则提取目录的路径,否则退出程序             
If .Show = -1 Then PathStr = .SelectedItems(1) Else Exit Sub        
 End With                 
 If Right(PathStr, 1) <> "\" Then PathStr = PathStr & "\"       
  For i = 1 To ChartCount '遍历所有图表              
 .Item(i).Chart.Export Filename:=PathStr & IIf(.Item(i).Chart.HasTitle, i, i) & ".JPG", FilterName:="JPG"        
 Next    
 End With
 End Sub 
  • 公众号:i95556
  • 计算机二级考生请关注
  • weinxin
  • 公众号:word_excel_ppt
  • 学习OFFICE请关注
  • weinxin
iexcel

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: