title: Excel VBA to save folder location after selection through a userform
body: <p>I am trying to give users the option to 'set' a default folder location, this would only be used to prefill further userform text boxes to save time having to go through the <code>msoFileDialogFolderPicker</code></p>
  <p>I did use chdir, but that was written into the vba script, this location will differ from user to user and should only need to be set once upon addon installation</p>
  <p>This is the code for the master folder selector:</p>
  <pre><code>Private Sub cmdfoldsel_Click()
      On Error GoTo err
      Dim fileExplorer As FileDialog
      Set fileExplorer = Application.FileDialog(msoFileDialogFolderPicker)
  
      'To allow or disable to multi select
      fileExplorer.AllowMultiSelect = False
  
      With fileExplorer
          If .Show = -1 Then 'Any folder is selected
              tbmasterloc.text = .SelectedItems.Item(1)
          Else ' else dialog is cancelled
              MsgBox &quot;You have cancelled the dialogue&quot;
              [folderPath] = &quot;&quot; ' when cancelled set blank as file path.
          End If
      End With
  err:
      Exit Sub
  End Sub
  </code></pre>
  <p>It is letting me choose the folder, but obviously the text disappears when I close ( I was using a close button with <code>unload me</code> but i thought that was deleting the text</p>
  <p>An example of the second userform which will call that folder location is here:</p>
  <pre><code>Private Sub UserForm_Initialize()
      copyfromtb.Value = mfs.tbmasterloc.text
  End Sub
  </code></pre>
  <pre><code>Private Sub copyfromcmd_Click()
  
      Dim fldr As FileDialog
      Dim sItem As String
  
      Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
      
      With fldr
          .Title = &quot;Select a Folder&quot;
          .AllowMultiSelect = False
          .InitialFileName = Application.DefaultFilePath
          '.InitialFileName = Application.GetSaveAsFilename()
          If .Show &lt;&gt; -1 Then GoTo NextCode
          sItem = .SelectedItems(1)
      End With
  NextCode:
      GetFolder = sItem
      copyfromtb.Value = sItem
  
      Set fldr = Nothing
  
  
  End Sub
  </code></pre>