在一个页面上将范围保存为图片文件/ pdf

时间:2015-10-04 12:02:08

标签: excel vba export copy-paste

我正在尝试将范围保存为图片文件。下面的代码(从另一篇文章中删除)有效,但我不想创建一个我需要删除的图表页面。有什么建议吗?

Sub savedeal()

Dim sSheetName As String
Dim oRangeToCopy As Range
Dim oCht As Chart
Dim myFileName As String, myPath As String

myFileName = Format(Now(), "dd-mmm-yy") & "-" & "DEAL.PNG"
myPath = "D:\Hughs Files\Google Drive\Work Folder\Polaris\Blog\"


Worksheets("BOOK").Range("B15:M45").CopyPicture xlScreen, xlBitmap

Set oCht = Charts.Add

With oCht
    .Export Filename:=myPath & "\" & myFileName, Filtername:="PNG"
End With
End Sub

1 个答案:

答案 0 :(得分:1)

这已经讨论多年,如果你想将它保存为图像,你将不得不添加图表,甚至插件使用图表。

您可以做的一件事就是将所需范围保存为PDF格式。

Sub RngToPDF()
    Dim sh As Worksheet, rng As Range, Fnm As String

    Set sh = Sheets("Book")
    Set rng = sh.Range("B15:M45")
    Fnm = "C:\Users\Dave\Downloads\TestMe.pdf"

    With sh.PageSetup
        .PrintArea = rng.Address
        .PrintGridlines = True
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    End With

    sh.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Fnm


End Sub