以横向格式从Excel表格导出PDF而不留空格

时间:2015-08-05 09:01:04

标签: excel vba excel-vba pdf shrink

需要解决我的苦难。以下代码有效,但问题是它将空白显示为完整站点。我想知道它是否可以缩小"那?

萎缩应该从@ Column" F"

开始

这是代码:

Private Sub CommandButton1_Click()
    Dim mySheets As Variant, sh

    mySheets = Array("Tabelle1")
    For Each sh In mySheets
        Sheets(sh).PageSetup.Orientation = xlLandscape

    Next
    Range("A1:CR33").Select

    Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\export.pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

    End If
End Sub

图中的插图。 这就是我得到的:http://www.bilder-upload.eu/show.php?file=e31421-1438765650.jpg

这就是我想要的:http://www.bilder-upload.eu/show.php?file=a9f566-1438765707.jpg

由于

1 个答案:

答案 0 :(得分:1)

我认为这就是你所追求的目标:

Private Sub CommandButton1_Click()     Dim mySheets As Variant,sh

mySheets = Array("Tabelle1")
For Each sh In mySheets
    Sheets(sh).PageSetup.Orientation = xlLandscape

Next

For Each the_cell In Range("A1:A33")
    If the_cell.Value = "" Then
        the_cell.EntireRow.Hidden = True
    Else
        Exit For
    End If
Next the_cell

Range("A1:CR33").Select


Selection.ExportAsFixedFormat Type:=xlTypePDF, fileName:=ThisWorkbook.Path & "\export.pdf", _
    quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

Range("A1:A33").EntireRow.Hidden = False

End Sub

基本上,我添加了一个循环 - 它会在第一个填充行之前隐藏单元格(并且在之后取消隐藏)

希望这对你有用