2009年9月4日金曜日

vbaで名証企業の住所データをexcelに取得

色々調べて結局下記を参考にした。

http://questionbox.jp.msn.com/qa4548743.html

Sub mSet()
Dim j As Long
Dim strURL As String
For j = 1 To 5
strURL = "URL;" & Sheets("Sheet1").Cells(j, 1).Value
Call データ読込み(strURL)
Next
End Sub
Sub データ読込み(strURL As String)
Dim i As Range
Set i = Sheets("Sheet2").Range("a" & Range("a" & Rows.Count).End(xlUp).Row).Offset(1)
With Sheets("Sheet2").QueryTables.Add(Connection:=strURL, Destination:=i)
.Name = "001_3"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "6"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub

もっとスマートなやり方があるのだろうが、もう疲れたので
データを取得してからexcelで並び替え、不要行削除などをして整えることにした。

0 件のコメント:

【宮下あきら】私立極道高校~男塾に通底するモチーフ

 「世紀末博狼伝サガ」こそが宮下あきらの最高傑作では・・・?と思う昨今だが、私立極道高校と男塾に共通するモチーフについてブログに残しておこう。 まずは舞台装置が私立高校?と私塾?というのは言うまでもないが・・・ 学校の支配者が巨人 男塾:大豪院邪鬼 私立極道高校:生徒会長 顔がな...