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 件のコメント:

ダイの大冒険→キテレツ大百科(藤田淑子)へのオマージュ?

ダイの大冒険を読み返していて一つのセリフが目に止まった。 「ゴメちゃん・・・! さよならは 言わないよ・・・」 (第335話「世界が輝く時」の巻より) これは・・・キテレツ大百科の最終回のセリフによく似ている! 「コロ助、さよならは言わないからね!」 (第331話(最終話)「愛の...