title: Get selected mail items in Outlook Explorer with VB.Net
body: <p>I am trying to convert some VBA code I have put together into an Outlook addin in order to avoid having to run the macros in reduced security environment.</p>
  
  <p>I know just enough VBA and VB6 to dabble in writing stuff I use for myself and this is my first foray into VB.Net. </p>
  
  <p>I just installed Visual Studio (Community Edition) and the conversion from VBA to has gone smoother than I expected thanks to suggestions by the IDE apart from one or two issues.</p>
  
  <p>One of these is trying to get the items selected in Outlook which I had based on the code provided here: <a href="https://msdn.microsoft.com/en-us/library/office/ff868001.aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/office/ff868001.aspx</a></p>
  
  <pre><code>Sub GetSelectedItems() 
      Dim myOlExp As Outlook.Explorer 
      Dim myOlSel As Outlook.Selection 
      Dim oMail As Outlook.MailItem 
      Dim x As Integer 
  
      myOlExp = Application.ActiveExplorer ' =&gt; This generates an error
      myOlSel = myOlExp.Selection 
      For x = 1 To myOlSel.Count 
          If myOlSel.Item(x).Class = OlObjectClass.olMail Then 
              Set oMail = myOlSel.Item(x) 
              ' Do Stuff 
          End If 
      Next x 
  End Sub 
  </code></pre>
  
  <p>I am unable to get around the error message generated by <code>Application.ActiveExplorer</code>.</p>
  
  <p>Any advice on how to convert this to VB.Net? I have searched high and low but all the examples I have found are VBA based.</p>
  
  <p>This <a href="https://stackoverflow.com/questions/10816828/getting-info-from-selected-mail-item-in-outlook-2010" title="SO Question">SO Question</a> comes close but I can't make the leap between the languages.</p>