Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从“保存到pdf VBA”宏中排除1张图纸_Vba_Excel - Fatal编程技术网

如何从“保存到pdf VBA”宏中排除1张图纸

如何从“保存到pdf VBA”宏中排除1张图纸,vba,excel,Vba,Excel,我有一个VBA代码可以很好地工作,除了我不知道如何从保存到PDF中排除一张工作表之外。我希望将名为“Control”的工作表从导出中排除并保存为PDF。你知道我应该如何或在哪里添加这个吗 谢谢 Sub CreatePDF() Dim saveAsName As String Dim WhereTo As String Dim sFileName As String Dim ws As Worksheet Dim myrange ' Retrieve information from Cont

我有一个VBA代码可以很好地工作,除了我不知道如何从保存到PDF中排除一张工作表之外。我希望将名为“Control”的工作表从导出中排除并保存为PDF。你知道我应该如何或在哪里添加这个吗

谢谢

Sub CreatePDF()

Dim saveAsName As String
Dim WhereTo As String
Dim sFileName As String
Dim ws As Worksheet
Dim myrange

' Retrieve information from Control sheet
Sheets("Control").Activate
Range("C4").Activate
periodName = ActiveCell.Value
Range("C5").Activate
saveAsName = ActiveCell.Value
Range("C6").Activate
WhereTo = ActiveCell.Value

Set myrange = Worksheets("Control").Range("range_sheetProperties")

' Check if Stamp-field has any value at all
' if not, add the current date.
If Stamp = "" Then Stamp = Date

' Assemble the filename
     sFileName = WhereTo & saveAsName & " (" & Format(CDate(Date), "DD-MMM-YYYY") & ").pdf"

' Format all sheets as landsape, autofit to 1 page and provide header
For Each ws In ActiveWorkbook.Worksheets

    With ws.PageSetup
    Application.PrintCommunication = False
    .Orientation = xlLandscape
    .Zoom = False
    .FitToPagesWide = 1
    .CenterHorizontally = True
    .ScaleWithDocHeaderFooter = False
    .AlignMarginsHeaderFooter = False
    .HeaderMargin = Application.InchesToPoints(0.31496062992126)
    Application.PrintCommunication = True

    DisplayHeader = Application.VLookup(ws.Name, myrange, 2, False)
        If Not IsError(DisplayHeader) Then
        .LeftHeader = "&L &""Arial,Bold""&11&K00-048DIVA: " & DisplayHeader
        Else: .LeftHeader = "&L &""Arial,Bold""&11&KFF0000WORKSHEET NOT DEFINED IN CONTROL SHEET "
        End If
    .CenterHeader = "&C &""Arial,Bold""&11&K00-048" & periodName
    End With

Next

' Save the File as PDF
    ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        sFileName, Quality _
        :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=True

     MsgBox "PDF document has been created and saved to : " & sFileName

' Make sure we open the Control sheet upon Exit
    Sheets("Control").Activate

End Sub

您可以在代码的开头隐藏工作表,然后在代码的结尾使其再次可见

测试:

' Retrieve information from Control sheet

Sheets("Control").Visible = False

'YOUR PDF CREATION CODE

Sheets("Control").Visible = True
Sheets("Control").Activate

我遇到了同样的问题,只是在导出功能期间隐藏了工作表,然后我把它带回来。。。代码如下:

 'Hide the log sheet to exclude from export
 ActiveWorkbook.Sheets("Log").Visible = xlSheetHidden

ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FilePath + Today + "\" + Range("H2").Value _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=True

'Bring back the log sheet to allow for editing
ActiveWorkbook.Sheets("Log").Visible = xlSheetVisible