title: Save PDF in landscape and with a dynamic range
body: <p>With a lot of help I managed to fabricate a user form where I can choose which worksheet to export as PDF. After that it automatically makes a email with the created PDF's as attachments.</p>
  <p>I am using the following code:</p>
  <pre><code>Private Sub CommandButton1_Click()
  Dim xSht As Worksheet
  Dim xFileDlg As FileDialog
  Dim xFolder As String
  Dim xYesorNo, I, xNum As Integer
  Dim xOutlookObj As Object
  Dim xEmailObj As Object
  Dim xUsedRng As Range
  Dim xArrShetts As Variant
  Dim xPDFNameAddress As String
  Dim xStr As String
  'xArrShetts = Array(&quot;test&quot;, &quot;Sheet1&quot;, &quot;Sheet2&quot;) 'Enter the sheet names you will send as pdf files enclosed with quotation marks and separate them with comma. Make sure there is no special characters such as \/:&quot;*&lt;&gt;| in the file name.
  xArrShetts = sheetsArr(Me)
  
  For I = 0 To UBound(xArrShetts)
      On Error Resume Next
      Set xSht = Application.ActiveWorkbook.Worksheets(xArrShetts(I))
      If xSht.Name &lt;&gt; xArrShetts(I) Then
          MsgBox &quot;Worksheet no found, exit operation:&quot; &amp; vbCrLf &amp; vbCrLf &amp; xArrShetts(I), vbInformation, &quot;Kutools for Excel&quot;
      Exit Sub
      End If
  Next
  
  
  Set xFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
  If xFileDlg.Show = True Then
      xFolder = xFileDlg.SelectedItems(1)
  Else
      MsgBox &quot;You must specify a folder to save the PDF into.&quot; &amp; vbCrLf &amp; vbCrLf &amp; &quot;Press OK to exit this macro.&quot;, vbCritical, &quot;Must Specify Destination Folder&quot;
      Exit Sub
  End If
  'Check if file already exist
  xYesorNo = MsgBox(&quot;If same name files exist in the destination folder, number suffix will be added to the file name automatically to distinguish the duplicates&quot; &amp; vbCrLf &amp; vbCrLf &amp; &quot;Click Yes to continue, click No to cancel&quot;, _
  vbYesNo + vbQuestion, &quot;File Exists&quot;)
  If xYesorNo &lt;&gt; vbYes Then Exit Sub
  For I = 0 To UBound(xArrShetts)
      Set xSht = Application.ActiveWorkbook.Worksheets(xArrShetts(I))
      
      xStr = xFolder &amp; &quot;\&quot; &amp; xSht.Name &amp; &quot;_&quot; &amp; Sheets(&quot;Voorblad&quot;).Range(&quot;D24&quot;).Value &amp; &quot;.pdf&quot;
      While Not (Dir(xStr, vbDirectory) = vbNullString)
          xStr = xFolder &amp; &quot;\&quot; &amp; xSht.Name &amp; xNum &amp; &quot;.pdf&quot;
      xNum = 100
         
      Wend
      Set xUsedRng = xSht.UsedRange
      If Application.WorksheetFunction.CountA(xUsedRng.Cells) &lt;&gt; 0 Then
          xSht.ExportAsFixedFormat Type:=xlTypePDF, Filename:=xStr, Quality:=xlQualityStandard
      End If
      xArrShetts(I) = xStr
  Next
  
  'Create Outlook email
  Set xOutlookObj = CreateObject(&quot;Outlook.Application&quot;)
  Set xEmailObj = xOutlookObj.CreateItem(0)
  With xEmailObj
      .Display
      .To = &quot;Administratie@holwerda.nl&quot;
      .CC = &quot;Jaap@holwerda.nl;Gerben@holwerda.nl;Peter@holwerda.nl&quot;
      .Subject = Sheets(&quot;Voorblad&quot;).Range(&quot;B24&quot;).Value &amp; &quot;_&quot; &amp; Sheets(&quot;Voorblad&quot;).Range(&quot;D24&quot;).Value
      
      
      
      
      For I = 0 To UBound(xArrShetts)
          .Attachments.Add xArrShetts(I)
      Next
      If DisplayEmail = False Then
          '.Send
      End If
  End With
  Unload Me
  End Sub
  
  Private Function sheetsArr(uF As UserForm) As Variant
    Dim c As MSForms.Control, strCBX As String, arrSh
    For Each c In uF.Controls
          If TypeOf c Is MSForms.CheckBox Then
              If c.Value = True Then strCBX = strCBX &amp; &quot;,&quot; &amp; c.Caption
          End If
    Next
    sheetsArr = Split(Mid(strCBX, 2), &quot;,&quot;) 'Mid(strCBX, 2) eliminates the first string character (&quot;,&quot;)
  
  End Function
  
  Private Sub CommandButton2_Click()
  Unload Me
  
  End Sub
  </code></pre>
  <p>I would like to export the PDF's in landscape style and in with a dynamic range.
  now when I export the files sometimes it doesn't fit to one page.</p>