title: Extra space in path when running VBA script on server
body: <p>I hope I'm able to explain this correctly, but I have an Excel file that runs a VBA script for turning an Excel file/data into a .htm file for web publication.</p>
  
  <p>On my own computer (Windows 10 Pro, Office 365) everything works as intended, but for some reason when I run the script on a different computer (specifically a remote server, running Windows 2016 Datacenter, Office 365) it adds a space in the filepath (behind "foldername") after executing/creating the htm file --> "C:\temp\foldername \filename.htm"
  With the added space in the end of the filepath I'm unable to grab/open the file, due to Windows then giving the "directory name is invalid" error.</p>
  
  <p>I tried searching Google/Stackoverflow, but I'm rather unsure on what keywords to use for finding an existing thread with the same issue.</p>
  
  <p>If it helps, here is the code section of the VBA for creating the file:</p>
  
  <pre><code>Option Explicit
  
  Private mstrAfasPublishPath As String
  
  Public Function GetAfasPublishPath() As String
  
    Dim strPath As String
  
    If Len(mstrAfasPublishPath) = 0 Then
      strPath = Environ$("AfasPublishPath")
      If Len(strPath) = 0 Then
        strPath = "C:\Temp\"
      Else
        NormalizePath strPath
      End If
      CreateDirectory strPath
      mstrAfasPublishPath = strPath
    End If
  
    GetAfasPublishPath = mstrAfasPublishPath
  
  End Function
  </code></pre>
  
  <hr>
  
  <pre><code>Public Function GetAfasErrorResult(ByVal Err As ErrObject) As Variant
  
    GetAfasErrorResult = Array(Err.Number, Err.Description, Err.Source)
  
  End Function
  </code></pre>
  
  <hr>
  
  <pre><code>Private Sub NormalizePath(strPath As String)
  
    Do While Right$(strPath, 1) = "\"
      strPath = Left$(strPath, Len(strPath) - 1)
    Loop
  
  End Sub
  </code></pre>
  
  <hr>
  
  <pre><code>Private Sub CreateDirectory(strPath As String)
  
    Dim strParentPath As String
  
    If Len(Dir$(strPath, vbDirectory)) = 0 Then
  
      strParentPath = Left$(strPath, InStrRev(strPath, "\"))
  
      If Len(strParentPath) &lt;= 2 Then
        RaiseError "The drive or share of path '" + strPath + "' is not available."
      End If
  
      If Len(Dir$(strParentPath, vbDirectory)) = 0 Then
        CreateDirectory strParentPath
      End If
      MkDir strPath
  
    End If
  
  End Sub
  </code></pre>
  
  <hr>
  
  <pre><code>Private Sub RaiseError(strMessage As String)
  
    Err.Raise vbObjectError, "AfasInternalFunctions", strMessage
  
  End Sub
  </code></pre>
  
  <hr>
  
  <pre><code>Private Function PathCombine(strPath As String, strAppend As String)
  
    If Right$(strPath, 1) = "\" Then
      If Left$(strAppend, 1) = "\" Then
        PathCombine = strPath + Mid$(strAppend, 2)
      Else
        PathCombine = strPath + strAppend
      End If
    ElseIf Left$(strAppend, 1) = "\" Then
      PathCombine = strPath + strAppend
    Else
      PathCombine = strPath + "\" + strAppend
    End If
  
  End Function
  </code></pre>