【问题标题】:Ungroup Sheets from an array in VBA从 VBA 中的数组中取消组合工作表
【发布时间】:2017-02-16 21:00:48
【问题描述】:

我一直在尝试简单地打印输出(使用单个按钮以 PDF 格式)的一张只有活动范围的工作表和一个位于另一张工作表中的图表。我一切正常,除了打印后,两张纸都组合在一起,我无法编辑我的图表。

我正在努力让同事在实时操作过程中做到这一点简单易行。现在我可以右键单击并选择“取消组合工作表”来修复它,但我讨厌每次都必须这样做(或解释需要这样做)。

我试图选择一个工作表,一个不同的工作表,只有一个工作表等。我不知道如何让 VBA 在最后取消组合工作表。有什么想法吗?

Sub CustomPrint()

'if statement to ask for file path
If Dir(Environ("commonprogramfiles") & "\Microsoft Shared\OFFICE" _
         & Format(Val(Application.Version), "00") & "\EXP_PDF.DLL") <> "" Then

        If FixedFilePathName = "" Then
            'Open the GetSaveAsFilename dialog to enter a file name for the PDF file.
            FileFormatstr = "PDF Files (*.pdf), *.pdf"
            fname = Application.GetSaveAsFilename("", filefilter:=FileFormatstr, _
                  Title:="Create PDF")

            'If you cancel this dialog, exit the function.
            If fname = False Then Exit Sub
        Else
            fname = FixedFilePathName
        End If

'Dynamic reference to RT drilling data
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range

Dim sht As Worksheet

Set sht = Worksheets("rt drilling data")
Set StartCell = Range("A1")

'Refresh UsedRange
  Worksheets("rt drilling data").UsedRange

'Find Last Row
  LastRow = sht.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

'Select Range
 sht.Range("A1:K" & LastRow).Select

Sheets("Chart Update").Activate
ActiveSheet.ChartObjects(1).Select

ThisWorkbook.Sheets(Array("chart update", "RT drilling data")).Select

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
    Filename:=fname, IgnorePrintAreas:=False
'If the export is successful, return the file name.
        If Dir(fname) <> "" Then RDB_Create_PDF = fname
    End If
 If OverwriteIfFileExist = False Then
            If Dir(fname) <> "" Then Exit Sub
        End If

   On Error GoTo 0

Worksheets("ws model updates").Select

End Sub

【问题讨论】:

  • 当您选择最后一张纸时,它们应该取消组合。我选择了一个组,和你一样,然后当我选择 sheet3 时,组解散。 Sheets(Array("Sheet1", "Sheet2")).Select Sheets("Sheet3").Select

标签: vba excel


【解决方案1】:

If Dir(fname) &lt;&gt; "" Then Exit Sub 将绕过Worksheets("ws model updates").Select

If OverwriteIfFileExist = False Then
    If Dir(fname) <> "" Then 

        Worksheets("ws model updates").Select
        Exit Sub

    End If
End If

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 2018-02-19
    • 2016-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多