title: Create MAPIFolder in PST using VBA
body: <p>I am trying to copy a structure of folders and subfolders from one Outlook PST to another one and have difficulties with the <code>Folders.Add()</code> statement:</p>
  
  <pre><code>Private Sub Process(S As MAPIFolder, T As MAPIFolder, RootLevel As Boolean, BeforeDate As Date)
  Dim N As NameSpace, F As MAPIFolder, G As MAPIFolder
  
      ' S is source folder (parameter)
      ' T is target folder (parameter)
      ' F is current source subfolder for recursion (private)
      ' G is target folder for recursion (private)
  
      Set N = Application.GetNamespace("MAPI")
  
      ' recurse through subfolders
      For Each F In S.Folders
          If F.Items.Count &lt;&gt; 0 Or F.Folders.Count &lt;&gt; 0 Then          ' process only if items or subfolders found
  
              If FoundFolder(T, F) Then                               ' this function works fine
                  Set G = T.Folders(F.Name)                           ' found - just assign
              Else
                  Set G = T.Folders.Add(F.Name, N.GetDefaultFolder(F.DefaultItemType))        ' not found - create
              End If
              '
              ' more code (working well)
              '                
              ' process next level without Root flag
              Process F, G, False, BeforeDate
          End If
      Next F
      Set F = Nothing
      Set G = Nothing
  End Sub
  </code></pre>
  
  <p>As long as in the <code>Folders.Add()</code> statement I don't specify the <code>Type</code> parameter at all, a folder with DefaultType olMailItem is created (because my root folder happens to be a mail folder). However, I want to create a folder of same type as the source folder.</p>
  
  <p>1st peculiar observation:</p>
  
  <ul>
  <li>VBA Help, MSN and others say that for Folders.Add(Name, Type) Type is Optional Long. </li>
  <li>VBA Editor says (in tooltip when typing) Type is MAPIFolder</li>
  </ul>
  
  <p>2nd observation:
  However I try to set the Type argument, I receive an error </p>
  
  <hr>
  
  <p>Error -2147024809 (80070057)</p>
  
  <p>Could not complete the operation. One or more parameter values are not valid</p>
  
  <hr>
  
  <p>I tried the following</p>
  
  <pre><code>' Type as Long
  Set G = T.Folders.Add(F.Name, 0)
  Set G = T.Folders.Add(F.Name, olMailItem)
  Set G = T.Folders.Add(F.Name, OlItemType.olMailItem)
  Set G = T.Folders.Add(F.Name, F.DefaultItemType) ' this is what I actually want
  ' Type as MAPIFolder
  Set G = T.Folders.Add(F.Name, F)
  Set G = T.Folders.Add(F.Name, N.GetDefaultFolder(F.DefaultItemType))
  </code></pre>
  
  <p>Error - Error - Error</p>
  
  <p>What to do to create a folder of the same type as the source folder F</p>
  
  <p>Anyone help .... please</p>
  
  <p>kind regards MikeD</p>