title: Create Excel Function to Load Part of an HTML File Into a Single Cell?
body: <p><strong>Background</strong><br/>
  Everyday, I upload hundreds of products into our database, each product contains a &quot;Short Description&quot;, &quot;Full Description&quot;, and &quot;Meta Description&quot;. I write these in an HTML template I built, and historically, I would just copy and paste each section of description to their corresponding cells. However, recently I've determined that it could be potentially faster to save each 'description'.html file (for reuse) and program an Excel function to pull the necessary data from the description file.</p>
  <p>I'm using Excel on Mac, and I'm pretty new to VBA.</p>
  <p><strong>Here is what I'd like to accomplish:</strong> Create a function that loads HTML content from a local file into an individual cell, and use a function parameter to determine what part of the html should be loaded into the cell.
  <a href="https://i.stack.imgur.com/lrR0G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lrR0G.png" alt="Excel Spreadsheet" /></a><br/></p>
  <p>First, I'm trying to 'just' get the html data into 'one' cell.<br/>
  Next, I need to separate the data by either 'short', 'long', or 'meta' description.</p>
  <p>Thus far, I'm stuck on just getting the html in the cell via VBA.</p>
  <p><strong>Here's my function:</strong></p>
  <pre><code>Function Description(InputFile, Part As String)
  
      Dim URL As String
      Dim IE As InternetExplorer
      Dim HTMLDoc As HTMLDocument
      Dim DescPart As String
      
      Set IE = New InternetExplorer
      URL = InputFile
      DescPart = Part
      
      With IE
          .navigate URL
          .Visible = False
          
          While .Busy Or .readyState &lt;&gt; READYSTATE_COMPLETE: DoEvents: Wend
          
          Set HTMLDoc = .document
      End With
      
      Select Case DescPart
          Case Short 'Get Short Description (Future)
              Description = HTMLDoc
          Case Full 'Get Full Description (Future)
              Description = HTMLDoc
          Case Meta 'Get Meta Description (Future)
              Description = HTMLDoc
      End Select
  End Function
  </code></pre>
  <p>I've read a lot about using VBA to read HTML (I don't understand most of it). The code above is more-or-less developed off of my research. I'm pretty sure that the traditional route of using 'Internet Explorer' won't work since this is built on Mac (I could be wrong). Would I need an AppleScript to scrape the HTML? All of the material I have found is for VBA on Windows.</p>
  <hr>
  <p>This might work on Mac, but I'm still running into an error... (The &quot;HTMLDocument&quot; type is not defined) Because Mac doesn't allow Active-x controls?</p>
  <pre><code>Function Description(InputFile, Part As String)
  
      Dim URL As String
      Dim HTMLdoc As HTMLDocument, HTMLdoc2 As HTMLDocument
      Dim DescPart As String
      
      URL = InputFile
      DescPart = Part
      
      Set HTMLdoc2 = New HTMLDocument
      Set HTMLdoc = HTMLdoc2.createDocumentFromURL(URL, &quot;&quot;)
      
      While HTMLdoc.readyState &lt;&gt; &quot;complete&quot;
          DoEvents
      Wend
      
      Select Case DescPart
          Case Short
              Description = HTMLdoc
          Case Full
              Description = HTMLdoc
          Case Meta
              Description = HTMLdoc
      End Select
  End Function
  </code></pre>