Excel 粘贴范围快照而不失真

Excel 粘贴范围快照而不失真,excel,vba,Excel,Vba,我使用这段代码将png格式的地图从excel导出到桌面上的Mycharts文件夹中。但是,当到达指定文件夹时,此图像会失真 Sub ExportMap() Dim day As Integer day = Worksheets("Control").Range("$J$1").Value Worksheets("Map").Range("B2:L43").CopyPicture xlScreen, xlPicture Application.DisplayAler

我使用这段代码将png格式的地图从excel导出到桌面上的Mycharts文件夹中。但是,当到达指定文件夹时,此图像会失真

Sub ExportMap()
    Dim day As Integer
    day = Worksheets("Control").Range("$J$1").Value
    Worksheets("Map").Range("B2:L43").CopyPicture xlScreen, xlPicture
    Application.DisplayAlerts = False
    Set oCht = Charts.Add
    If day = 1 Then
    With oCht
        .Paste
        .Export Filename:="...\Mycharts\FCT_Day_1.png",  filtername:="PNG"
        .Delete
    End With
    End If
    If day = 2 Then
    With oCht
        .Paste
        .Export Filename:="...\Mycharts\FCT_Day_2.png", filtername:="PNG"
        .Delete
    End With
    End If
    If day = 3 Then
    With oCht
        .Paste
        .Export Filename:="..\Mycharts\FCT_Day_3.png", filtername:="PNG"
        .Delete
    End With
    End If   
End Sub
使用并调整其大小以适应源的像素大小,以避免失真和像素化

Sub ExportMap()
    Dim dy As Integer, pxHeight As Integer, pxWidth As Integer
    Dim oCht As Excel.ChartObject

    dy = Worksheets("Control").Range("J1").Value  '<~~ J1 is text; it's not going anywhere

    With Worksheets("Map")
        With .Range("B2:L43")
            .CopyPicture xlScreen, xlPicture
            'get the dimensions of the screen shot
            pxHeight = .Height
            pxWidth = .Width
        End With
        Application.DisplayAlerts = False
        With .ChartObjects.Add(10, 10, pxWidth, pxHeight)
            Select Case dy
                Case 1, 2, 3
                    .Chart.Paste
                    .Chart.Export Filename:=Environ("TMP") & "\FCT_Day_" & dy & ".png", filtername:="PNG"
                    .Delete
                Case Else
                    'do nothing
            End Select
        End With
    End With
End Sub
子导出映射()
Dim dy为整数,pxHeight为整数,pxWidth为整数
将oCht设置为Excel.ChartObject
dy=工作表(“控制”)。范围(“J1”)。值“使用一个参数,并调整其大小以适应源的像素大小,以避免失真和像素化

Sub ExportMap()
    Dim dy As Integer, pxHeight As Integer, pxWidth As Integer
    Dim oCht As Excel.ChartObject

    dy = Worksheets("Control").Range("J1").Value  '<~~ J1 is text; it's not going anywhere

    With Worksheets("Map")
        With .Range("B2:L43")
            .CopyPicture xlScreen, xlPicture
            'get the dimensions of the screen shot
            pxHeight = .Height
            pxWidth = .Width
        End With
        Application.DisplayAlerts = False
        With .ChartObjects.Add(10, 10, pxWidth, pxHeight)
            Select Case dy
                Case 1, 2, 3
                    .Chart.Paste
                    .Chart.Export Filename:=Environ("TMP") & "\FCT_Day_" & dy & ".png", filtername:="PNG"
                    .Delete
                Case Else
                    'do nothing
            End Select
        End With
    End With
End Sub
子导出映射()
Dim dy为整数,pxHeight为整数,pxWidth为整数
将oCht设置为Excel.ChartObject

dy=工作表(“控制”).Range(“J1”).Value“请编辑您的问题,以包含实际描述您所面临问题的标题。请编辑您的问题,以包含实际描述您所面临问题的标题。谢谢。它解决了我的问题,也缩短了代码。再次非常感谢您的快速回复。谢谢吉普吉。它解决了我的问题,也缩短了代码。再次感谢您的快速回复。