求助:VBA代码哪里有问题。

weixin_47875022 2025-01-27 09:10:28

各位老大

大家好。

我想把EXCEL单元格里的图片批量导出来,并且以人名来命名,写完的代码哪里有问题,拜托大家指导一下。

感谢。

Sub Rename()

Application.ScreenUpdating = False

On Error Resume Next

MkDir ThisWorkbook.Path & "\pho"

For Each pic In ActiveSheet.Shapes

    If pic.Type = msoPicture Then

        rn = pic.TopLeftCell.Offset(0, -1).Value

        pic.Copy

        With ActiveSheet.ChartObjects.Add(0, 0, pic.Width, pic.Height).Chart

            .Parent.Select

            .Paste

            .Export ThisWorkbook.Path & "\pho" & rn & ".jpg"

            .Parent.Delete

        End With

    End If

Next

MsgBox "导出图片完成!"

Application.ScreenUpdating = True

End Sub

...全文
99 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
渡老 02-04
  • 打赏
  • 举报
回复

Sub Rename()

Application.ScreenUpdating = False

On Error GoTo ErrorHandler

MkDir ThisWorkbook.Path & "\pho\"

For Each pic In ActiveSheet.Shapes
    If pic.Type = msoPicture Then
        rn = pic.TopLeftCell.Offset(0, -1).Value
        pic.Copy
        With ActiveSheet.ChartObjects.Add(0, 0, pic.Width, pic.Height).Chart
            .Parent.Select
            .Paste
            .Export ThisWorkbook.Path & "\pho\" & rn & ".jpg"
            .Parent.Delete
        End With
    End If
Next

MsgBox "导出图片完成!"

Application.ScreenUpdating = True
Exit Sub

ErrorHandler:
MsgBox "发生错误: " & Err.Description
Application.ScreenUpdating = True

End Sub

吴景怡 02-03
  • 打赏
  • 举报
回复

1

2,503

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧