从VBA中的数组中取消分组表格

我一直在尝试使用只有有效范围的一张纸和位于另一张纸上的一张图轻松打印(使用单个button的PDF)。 我有一切工作,除了我打印后,两张纸都分组在一起,我不能编辑我的图表。

我试图在实时操作过程中让同事万无一失。 现在我可以右键单击并select“取消分组”来修复它,但我讨厌每次都必须这样做(或者解释它需要完成)。

我试图select一张纸,一张不同的纸张,只有一张纸等等。我不知道如何让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 

If Dir(fname) <> "" 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