2016-10-07 8 views
1

私はアクティブな範囲と1つのチャートが別のシートにある1枚のシートから簡単に(1つのボタンを使ってPDFで)印刷しようとしています。印刷した後でも、両方のシートがグループ化されていて、グラフを編集できない場合を除いて、すべてが機能しています。VBAの配列からシートのグループを解除する

私はリアルタイム操作中の同僚にとってこれを簡単かつ簡単にしようとしています。今すぐ右クリックして[シートのグループを解除]を選択して修正することができますが、その都度行う必要はありません(または完了する必要があることを説明してください)。

私は、シート、別のシート、1枚のシートなどを選択しようとしました。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 
+1

をバイパスします。あなたと同じグループを選択し、次にsheet3を選択すると、そのグループは解散します。 シート(Array( "Sheet1"、 "Sheet2")) シート( "Sheet3")を選択してください – Hrothgar

答えて

0

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 
+0

を選択してください。本当にありがとう。 – Katie

関連する問題