0

I am trying to download SEC filings (10-K, 8-K etc) from SEC website using Excel vba. I am using getelementsbytagname to identify the url for the filing. However when i use "URLDownloadToFile" private function, I am not able to get the file downloaded instead i get the "Inline XBRL Viewer.htm" file which does not contain any of the filing text. Below is the code that i am using:

htmlCol3 = htmlDoc1.getElementsByTagName("a")
For Each htmlInput3 In htmlCol3
If Left$(htmlInput3, 36) = "https://www.sec.gov/ix?doc=/Archives" Then
URL1 = Trim(htmlInput3)
buf = Split(URL1, ".")
ext = buf(UBound(buf))
If dt >= rptdt Then
strSavePath = FOL & "\" & CIK & "_" & FIL & "_" & str1 & "." & ext
ret = URLDownloadToFile(0, URL1, strSavePath, 0, 0)

Below is the download file function I am using:

Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _
szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

I am trying to get the first url from the Document column in the top table from this webpage:

https://www.sec.gov/Archives/edgar/data/769397/000076939719000016/0000769397-19-000016-index.htm

Pawel Czyz
  • 1,651
  • 4
  • 17
  • 21
msksantosh
  • 379
  • 4
  • 19

1 Answers1

1

To get the actual filing, strip out the ix?doc= bit so that you have a URL that starts https://www.sec.gov/Archives/...

e.g.

URL1 = Replace(URL1, "https://www.sec.gov/ix?doc=", "https://www.sec.gov")
pdw
  • 884
  • 4
  • 5