从excel导出时如何删除图像边框?

从excel导出时如何删除图像边框?,excel,vba,Excel,Vba,这是我的代码,将图像从excel导出到文件 For Each oShape In ActiveSheet.Shapes strImageName = oShape.TopLeftCell.Row & "_" & oShape.TopLeftCell.Column If oShape.Type = msoPicture Then oShape.Select 'Picture format initialization

这是我的代码,将图像从excel导出到文件

For Each oShape In ActiveSheet.Shapes
    strImageName = oShape.TopLeftCell.Row & "_" & oShape.TopLeftCell.Column
    If oShape.Type = msoPicture Then
        oShape.Select
        'Picture format initialization
        Selection.ShapeRange.PictureFormat.Contrast = 0.5: Selection.ShapeRange.PictureFormat.Brightness = 0.5: Selection.ShapeRange.PictureFormat.ColorType = msoPictureAutomatic: Selection.ShapeRange.PictureFormat.TransparentBackground = msoFalse: Selection.ShapeRange.Fill.Visible = msoFalse: Selection.ShapeRange.Line.Visible = msoFalse: Selection.ShapeRange.Rotation = 0#: Selection.ShapeRange.PictureFormat.CropLeft = 0#: Selection.ShapeRange.PictureFormat.CropRight = 0#: Selection.ShapeRange.PictureFormat.CropTop = 0#: Selection.ShapeRange.PictureFormat.CropBottom = 0#: Selection.ShapeRange.ScaleHeight 1#, msoTrue, msoScaleFromTopLeft: Selection.ShapeRange.ScaleWidth 1#, msoTrue, msoScaleFromTopLeft
        '/Picture format initialization
        Application.Selection.CopyPicture
        Set oDia = ActiveSheet.ChartObjects.Add(0, 0, oShape.Width, oShape.Height)
        Set oChartArea = oDia.Chart
        oDia.Activate
        With oChartArea
            .ChartArea.Select
            .Paste
            .Export ("D:\images\" & strImageName & ".jpg")
        End With
        oDia.Delete 'oChartArea.Delete
    End If
Next
原始图像不存在边框,但结果文件中存在超出图像大小的边框:

从excel导出时如何保留原始图像?

这有帮助吗?(未经测试)

边框位于要将图像放入导出的图表上,而不是图像本身。因此:

Set oChartArea=oDia.Chart
'无需激活ChartObject
奥恰特地区
.ChartArea.Format.Line.Visible=msoFalse'无轮廓
.ChartArea.Format.Fill.Visible=msoFalse'无背景
.ChartArea.Paste“无需使用选择
.Export(“D:\images\”和strimagname&“.jpg”)
以
oDia.删除
您只需在即时窗口(VBE中的Ctrl+G)中运行
ActiveSheet.ChartObjects.Add 0、0、100、100
,并观察ChartObject上的默认设置(包括大纲),就可以更清楚地看到这一点

'Your code....
oDia.Activate
Activesheet.Shapes(oDia.name).Line.Visible = msoFalse
With oChartArea
'Rest of code....