title: Unselect or Deselect Worksheet
body: <p>I have a workbook with x worksheets.
  And a button (commandbutton1) in Sheet1 which opens a userform with two checkboxes and a Preview Button to choose between 2 sheets to preview in PDF.</p>
  
  <p>Here’s my Preview button code.</p>
  
  <pre><code>Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  
  Private Sub CommandButton1_Click()
      Dim i As Integer
      Dim CheckBoxName As String
  
      For i = 1 To 2
          CheckBoxName = "CheckBox" &amp; i
          If Me.Controls(CheckBoxName).Value = True Then
              Sheets(Me.Controls(CheckBoxName).Caption).Select (False)
          End If
      Next i
  
      ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:="D:\Preview.pdf"
  
      Unload Me
  
      Dim File As String
      File = "D:\Preview.pdf"
      ShellExecute 0, "Open", File, "", "", vbNormalNoFocus
  End Sub
  </code></pre>
  
  <p>Now, the problem is that Sheet1 is always included in the preview file since it’s the sheet containing commandbutton1.</p>
  
  <p>So is there a way to deselect sheet1 before exporting sheets 6 &amp; 21 ??</p>
  
  <p>I also tried another way but it always stuck at this line (Sheets(Array(SheetNames)).Select)</p>
  
  <pre><code>Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  
  Private Sub CommandButton1_Click()
      Dim i As Integer
      Dim CheckBoxName As String
      Dim SheetNames As String
  
      For i = 1 To 2
          CheckBoxName = "CheckBox" &amp; i
          If Me.Controls(CheckBoxName).Value = True Then
              SheetNames = SheetNames &amp; Me.Controls(CheckBoxName).Caption &amp; ","
          End If
      Next i
  
      SheetNames = Mid(SheetNames, 1, Len(SheetNames) - 1)
  
      Sheets(Array(SheetNames)).Select
  
      ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:="D:\Preview.pdf"
  
      Unload Me
  
      Dim File As String
      File = "D:\Preview.pdf"
  
      ShellExecute 0, "Open", File, "", "", vbNormalNoFocus
  End Sub
  </code></pre>
  
  <p>Any help with any of these please ??</p>
  
  <p>Thank u in advance.</p>