title: Looping to save a range as a pdf file in a new folder created in the current directory
body: <p>I want to save a range of an excel sheet into a pdf file in a new folder created automatically in the current directory (I need to do the same for all excel sheets in the documents)
  But each time I run the code there's no file saved or a folder created on my desktop ( the excel file on which I'm working is located in the desktop)<br />
  I will be grateful for your help
  Thanks
  here's the function that I wrote</p>
  <pre><code>Sub PDF_saving()
      
      Dim tbAllBoxes() As Variant
          'Put all you textboxes into an array
          tbAllBoxes = Array(SuiviConso.Controls(&quot;Textbox2&quot;), SuiviConso.Controls(&quot;Textbox3&quot;), SuiviConso.Controls(&quot;Textbox4&quot;), SuiviConso.Controls(&quot;Textbox5&quot;), SuiviConso.Controls(&quot;Textbox6&quot;), SuiviConso.Controls(&quot;Textbox7&quot;), SuiviConso.Controls(&quot;Textbox8&quot;), SuiviConso.Controls(&quot;Textbox9&quot;))
          Dim tballLabels() As Variant
          tballLabels = Array(SuiviConso.Controls(&quot;Label2&quot;), SuiviConso.Controls(&quot;Label3&quot;), SuiviConso.Controls(&quot;Label4&quot;), SuiviConso.Controls(&quot;Label5&quot;), SuiviConso.Controls(&quot;Label6&quot;), SuiviConso.Controls(&quot;Label7&quot;), SuiviConso.Controls(&quot;Label8&quot;), SuiviConso.Controls(&quot;Label9&quot;))
          Dim shAllSheets As Variant
          'Put all your worksheets into an array
          shAllSheets = Array(ThisWorkbook.Sheets(&quot;sheet2&quot;), ThisWorkbook.Sheets(&quot;sheet3&quot;), ThisWorkbook.Sheets(&quot;sheet4&quot;), ThisWorkbook.Sheets(&quot;sheet5&quot;), ThisWorkbook.Sheets(&quot;sheet6&quot;), ThisWorkbook.Sheets(&quot;sheet7&quot;), ThisWorkbook.Sheets(&quot;sheet8&quot;), ThisWorkbook.Sheets(&quot;sheet9&quot;))
      
      Dim wbA As Workbook
      Dim lastrow2 As Integer
      Dim strPath, path  As String
      Dim filename As String
      Dim rng As Range
      
      
      For i = 1 To UBound(shAllSheets)
          If tbAllBoxes(i).Value &lt;&gt; &quot;&quot; Then
      filename = shAllSheets(i).Range(&quot;A1&quot;).Value &amp; Format(Date, &quot;MM-DD-YYYY&quot;) &amp; &quot; rapport de consommation &quot; &amp; &quot;.pdf&quot;
      strPath = path &amp; filename
      MkDir strPath
      lastrow2 = shAllSheets(i).Range(&quot;A&quot; &amp; Rows.Count).End(xlUp).Row + 1
      Set rng = shAllSheets(i).Range(&quot;A1 : J&quot; &amp; lastrow2)
      rng.ExportAsFixedFormat Type:=xlTypePDF, filename:=ActiveWorkbook.path &amp; filename
      End If
      Next i
      End Sub
  </code></pre>