首页 > 解决方案 > 如何将exel打印为PDF,不包括第一张纸

问题描述

我正在尝试将 excel 工作簿打印为 pdf,但从 PDF 中排除标题为基本信息的第一张工作表。目前,整个工作簿都包含在 PDF 中

Option Explicit

Sub CreatePDF()
  Dim IsCreated As Boolean
  Dim PdfFile As String, Title As String
  Dim s As Worksheet
  Dim DoNotInclude As String

  With Application
    .DisplayAlerts = False
    .ScreenUpdating = False
  End With

  Title = "I&T Plan for " & Worksheets("Basic Information").Range("C7").Value
  PdfFile = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\" & Title & ".pdf"
  
    Sheets("Front Sheet").Select
   
  
  DoNotInclude = ("Basic Information")
  
    For Each s In ActiveWorkbook.Worksheets
    If s.Visible = True Then
      If InStr(DoNotInclude, s.Name) = 0 Then
          s.Select (False)
      End If
    End If
  Next

  With ActiveSheet
    .ExportAsFixedFormat Type:=xlTypePDF, fileName:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
  End With

  Sheets("Front Sheet").Select

  MsgBox "Created PDF file on the desktop", vbOKOnly, "I&T PDF"

  With Application
    .DisplayAlerts = True
    .ScreenUpdating = True
  End With


End Sub

标签: excelvbapdf

解决方案


选择除第一张以外的所有工作表:

Dim x As Long, wb As Workbook
    
Set wb = ActiveWorkbook
wb.Sheets(2).Select
For x = 3 To Sheets.Count
    wb.Sheets(x).Select False
Next x

打印...


推荐阅读