您的位置:来学习素材网 > 办公软件 > excel教程

猜你喜欢

2023-10-06 20:46
导出文件夹内多个Excel文件的图片
[文章导读]前面我们讲过怎么导出Excel工作表中的图片。那么如何将一个文件夹内的全部Excel中的sheet1工作表的图片导出。

如果sheet1 有多张图片,即命名为“Excel表名(1),Excel表名(2)”这样循环

效果动态图:

详细VBA源码:

Sub 保存图片()

Dim MyPath$, myFolder$, myName$

Dim wb As Workbook, Sh As Worksheet, shp As Shape, m%, n%

Application.ScreenUpdating = False

Application.DisplayAlerts = False

MyPath = ThisWorkbook.Path

myFolder = MyPath & "\图片\"

If Len(Dir(myFolder, vbDirectory)) = 0 Then MkDir myFolder

myName = Dir(MyPath & "\*.xls", vbDirectory)

Do While myName <> ""

If myName <> ThisWorkbook.Name Then

n = 0

Set wb = Workbooks.Open(MyPath & "\" & myName) 'Filename:=MyPath & "\" & myName '& ".xls" ', Password:=""

For Each Sh In wb.Sheets

For Each shp In Sh.Shapes

n = n + 1

shp.CopyPicture

With Sh.ChartObjects.Add(0, 0, shp.Width, shp.Height).Chart

.Paste

.Export myFolder & myName & "(" & n & ").JPG", "JPG"

.Parent.Delete

End With

Next

Next

wb.Close savechanges:=False

End If

m = m + n

myName = Dir

Loop

MsgBox "保存了 " & m & "张图片"

Application.DisplayAlerts = True

Application.ScreenUpdating = True

End Sub

Excel技巧

声明:本站拒绝任何弹窗、插件以及广告联盟的广告,本QQ号(254031582)只解决会员问题,素材失效问题,软件使用问题一律不回。

为广大设计朋友提供平面设计素材和教材、PSD素材、C4D模型、3DMAX模型、AE模板、矢量模板等下载

苏ICP备2023039977号-2

Copyright © 2010-2020laixuexi.cc. All Rights Reserved .