打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
104.将选择定单元格作成镜像图片

'###############################################################

'函数作用:将选择定单元格作成镜像图片

'###############################################################

Sub Test()

    'ExportRangeAsImage "d:\a.gif", "GIF"

    'ExportRangeAsImage "d:\a.JPG", "JPG"

End Sub

Sub ExportRangeAsImage(varFileName As Variant, ImageFilter As String)

    Dim objChart As ChartObject

    Dim chtChart As Chart

    Dim picPicture As Picture

    Dim sglWidth As Single

    Dim sglHeight As Single

    Dim rngSelection As Range

    Dim blnRet As Boolean

    On Error GoTo ExportRangeError

    Set rngSelection = Selection

    With Application

        .StatusBar = "Exporting range..."

        .ScreenUpdating = False

    End With

    rngSelection.CopyPicture Appearance

    = xlScreen, Format

    = xlPicture

    Set objChart = ActiveSheet.ChartObjects.Add(0, 0, 5000, 5000)

    Set chtChart = objChart.Chart

    objChart.Activate

    With chtChart

        .ChartArea.Select

        .Paste

        Set picPicture = .Pictures(1)

    End With

    With picPicture

        sglWidth = .Width + 7

        sglHeight = .Height + 7

        .Left = 0

        .Top = 0

    End With

    With objChart

        .Border.LineStyle = xlNone

        .Width = sglWidth

        .Height = sglHeight

    End With

    blnRet = chtChart.Export(FileName

    = varFileName, Filtername    = ImageFilter, Interactive

    = False)

    objChart.Delete

    Set objChart = Nothing

    Application.StatusBar = False

    If Not blnRet Then

        MsgBox "Sorry, the export failed: please verify that you " & vbLf & _

            "have the appropriate filter installed on your PC.", vbExclamation, AT & " ‐ Export range as image"

    Else

    End If

Continue:

    With Application

        .StatusBar = False

        .ScreenUpdating = True

    End With

    Exit Sub

ExportRangeError:

    MsgBox "Sorry, the export failed: please verify that you " & vbLf & _

        "have the appropriate filter installed on your PC." & vbLf & _

        "Error nr. " & Err.Number & ": " & Err.Description, vbExclamation, AT & " ‐ Export range as image"

    If Not objChart Is Nothing Then objChart.Delete

    Resume Continue

End Sub

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
VBA程序集(第1辑)
Excel VBA编程的常用代码
搜集各种Excel VBA的命令供参考!
Excel_VBA从关闭的工作簿中取值多种实现方法(代码)
编写高效Excel VBA代码的最佳实践
VBA数组基础学习
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服