title: Cell Value String Variable in Path Errors to "Bad File Name or Number"
body: <p>Sorry for the long one, and it's probably something simple that I'm overlooking after so much time.</p>
  <p>I'm writing a small program that in just a few clicks, pulls data from an actor's &quot;deal memo&quot; pdf and put's that info into one of four possible excel templates (in different sheets) to export as a new &quot;contract&quot; pdf.</p>
  <p>The application identifies certain key words/values from other cells that determines which sheet/template is used.</p>
  <p>The issue comes at the following step:
  -Based on the keywords, I need the exported document to identify if a series of folders are created, and if not, create them, and step in to create more relevant folders before finally saving the file.</p>
  <p>The structure example is as follows, relevant created folders in <strong>Bold</strong>:</p>
  <p>C:\Work Folder\ <strong>Deal Memo to Contract\Exported Contracts\Episode Number\Actor Name\Contract Type\final.pdf</strong></p>
  <p>Each folder name is created based on variables pulled from cell values. It works just fine when I put the string variables in quotes for testing, and even when the variables are stated by themselves, it pastes the proper path in the admin cells as shown in the following picture - Range A14:A21</p>
  <p>Screenshot of Dashboard Page, admin column to be hidden</p>
  <p><a href="https://i.stack.imgur.com/8R85B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8R85B.png" alt="enter image description here" /></a></p>
  <p>But even though it looks like a proper path address in the cells, VBA throws a</p>
  <blockquote>
  <p>Runtime error 52:Bad file name or number on line 56, &quot;PlayerExFolder = Dir(PlayerExPath, vbDirectory)&quot;</p>
  </blockquote>
  <p>Like I said, it's probably something simple. Any help would be great as I'm still pretty new to this.  Oh, and I'm working on the Daily_Direct section of the if statements, the others will be identical once this starts working. Thanks!</p>
  <p>UPDATE - It turns out that I had narrowed it down to what I thought were extra spaces that were ruining the path/folder creation. They were invisible &quot;Ghost&quot; characters. Ended up using the Clean function on the cells that were being used to name the folders. Hope this helps someone in the future.</p>
  <pre><code>Sub export_pdf()
  
  Application.ScreenUpdating = False
  
  Dim MainExPath As String
  Dim MainExFolder As String
  MainExPath = Worksheets(&quot;Deal2Contract&quot;).Range(&quot;C3&quot;).Value &amp; &quot;\Exported Contracts&quot;
  MainExFolder = Dir(MainExPath, vbDirectory)
      
      If MainExFolder = vbNullString Then
          Answer = MsgBox(&quot;An export folder for the generated contracts does not exist, I will create one for you&quot;, vbOKCancel, &quot;Create Contract Export Folder?&quot;)
          Select Case Answer
              Case vbOK
                  VBA.FileSystem.MkDir (MainExPath)
              Case Else
          End Select
      End If
  
      Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A15&quot;).Value = MainExPath
  
  Dim EpiExPath As String
  Dim EpiExFolder As String
  Dim currEp As Integer
  currEp = Worksheets(&quot;Data&quot;).Range(&quot;F14&quot;).Value
  EpiExPath = Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A15&quot;).Value &amp; &quot;\&quot; &amp; currEp
      Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A17&quot;).Value = EpiExPath
      
  Dim PlayerExPath As String
  Dim PlayerExFolder As String
  Dim CurrPlayer As String
  CurrPlayer = Worksheets(&quot;Data&quot;).Range(&quot;F8&quot;).Value
  PlayerExPath = Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A17&quot;).Value &amp; &quot;\&quot; &amp; CurrPlayer
      Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A19&quot;).Value = PlayerExPath
       
  Dim TypeExPath As String
  Dim TypeExFolder As String
  Dim CurrType  As String
  CurrType = Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A7&quot;).Value
  TypeExPath = Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A19&quot;).Value &amp; &quot;\&quot; &amp; CurrType
      Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A21&quot;).Value = TypeExPath
      
      
      If Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A7&quot;).Value = &quot;Weekly_Direct&quot; Then
      
          ElseIf Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A7&quot;).Value = &quot;Weekly_Loan&quot; Then
          
          ElseIf Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A7&quot;).Value = &quot;Daily_Direct&quot; Then
              
              EpiExFolder = Dir(EpiExPath, vbDirectory)
                      If EpiExFolder = vbNullString Then
                          VBA.FileSystem.MkDir (EpiExPath)
                      Else
                      End If
              
              PlayerExFolder = Dir(PlayerExPath, vbDirectory)
                      If PlayerExFolder = vbNullString Then
                          VBA.FileSystem.MkDir (PlayerExPath)
                      Else
                      End If
                  
              TypeExFolder = Dir(TypeExPath, vbDirectory)
                      If TypeExFolder = vbNullString Then
                          VBA.FileSystem.MkDir (TypeExPath)
                      Else
                      End If
              
              'dateExFolder = Dir(dateExPath, vbDirectory)
                      'If typeExFolder = vbNullString Then
                       '   VBA.FileSystem.MkDir (currType)
                      'Else
                      'End If
                       
          ElseIf Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A7&quot;).Value = &quot;Daily_Loan&quot; Then
      
      
      End If
    
  Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A15&quot;).WrapText = False
  Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A17&quot;).WrapText = False
  Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A19&quot;).WrapText = False
  Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A21&quot;).WrapText = False
  Worksheets(&quot;Deal2Contract&quot;).Range(&quot;A23&quot;).WrapText = False
  Application.ScreenUpdating = True
  
  End Sub
  </code></pre>