Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks again mwolfe. I've posted my code below but what you provided is much more elegant. I know that the SICs are only 4 digits so I was lazy and made that an assumption in the code and that could throw up errors in the future. You can see how I did it in the commented out part.</p> <pre class="lang-vb prettyprint-override"><code>Sub GetSICs() Application.ScreenUpdating = False Dim AWBN As String Dim ASN As String Dim CIK As String Dim NUM_FILES_TO_GET As Long Dim COUNTER As Long Dim SICTagPos As Integer Dim SIC As String Set IEbrowser = CreateObject("InternetExplorer.application") IEbrowser.Visible = False AWBN = ActiveWorkbook.Name ASN = ActiveSheet.Name Workbooks(AWBN).Sheets(ASN).Range("A1").Select ActiveCell.Offset(0, 11) = "SIC" NUM_FILES_TO_GET = Application.WorksheetFunction.CountA(Range("A:A")) For COUNTER = 1 To 3 'NUM_FILES_TO_GET Application.StatusBar = "Counter = " &amp; COUNTER 'SICTagPos = 0 CIK = ActiveCell.Offset(COUNTER, 2) IEbrowser.Navigate URL:="http://www.sec.gov/edgar/searchedgar/companysearch.html" Do DoEvents Loop Until IEbrowser.readyState = 4 Set frm = IEbrowser.Document.forms(0) frm("CIK").Value = CIK frm.submit While IEbrowser.Busy Or IEbrowser.readyState &lt;&gt; 4: DoEvents: Wend SIC = ExtractSIC(IEbrowser.Document.body.innerhtml) 'SICTagPos = InStr(1, IEbrowser.Document.body.innerhtml, "SIC=") 'SIC = Right(Left(IEbrowser.Document.body.innerhtml, SICTagPos + 7), 4) ActiveCell.Offset(COUNTER, 11).NumberFormat = "@" ActiveCell.Offset(COUNTER, 11) = SIC Next Application.StatusBar = False Application.ScreenUpdating = True End Sub Function ExtractSIC(SourceHtml As String) As String Const PrefixChars As String = "&amp;amp;SIC=" Const SuffixChars As String = "&amp;" Dim StartPos As Long, EndPos As Long StartPos = InStr(SourceHtml, PrefixChars) If StartPos = 0 Then Exit Function StartPos = StartPos + Len(PrefixChars) EndPos = InStr(StartPos, SourceHtml, SuffixChars) - 1 ExtractSIC = Mid(SourceHtml, StartPos, EndPos - StartPos + 1) End Function </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload