Sub Test1()
Dim row As Integer: row = 1
Dim code As Integer: For code = 1300 To 3000
For Each T In Array("T", "Q", "OS", "OJ")
Dim rss As String: rss = "=RSS|'[Code].[T]'!銘柄名称"
rss = Replace(rss, "[Code]", CStr(code))
rss = Replace(rss, "[T]", T)
Cells(1, 1).Value = code
Cells(1, 2).Formula = rss
DoEvents
If Cells(1, 2).Text <> "#N/A" Then
Debug.Print row, code, T, Cells(1, 2).Value
row = row + 1
Exit For
End If
Next
Next
End Sub
みごとに299銘柄で止まりますってこと
楽天RSSのブログ記事(古い順)
[楽天RSS] EXCEL300銘柄制限
[楽天RSS] VB6で300銘柄制限を突破
Private Sub Form_Load()
Dim count As Integer: count = 0
Dim code As Integer: For code = 1300 To 3000
For Each T In Array("T", "Q", "OS", "OJ")
Dim topic As String
topic = "RSS|[Code].[T]"
topic = Replace(topic, "[Code]", CStr(code))
topic = Replace(topic, "[T]", T)
On Error Resume Next
Label1.LinkMode = 0 '0.なし
Label1.LinkTopic = topic
Label1.LinkItem = "銘柄名称"
Label1.LinkMode = 1 '1.自動
If Err.Number = 0 Then
count = count + 1
Debug.Print count, code, T, Label1.Caption
Exit For
End If
DoEvents
Next
Next
End Sub
遅いね。でも一応300銘柄以上回ります。
ちなみにDDEは20年近く昔の技術なので今のVB2005(VB.NET)にはDDELink機能はもうありませんよ。と
[楽天RSS] VB.NETでやってみる
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim enc As Encoding = Encoding.GetEncoding("Shift-JIS")
Dim count As Integer = 0
For code As Integer = 1300 To 3000
For Each T As String In New String() {"T", "Q", "OS", "OJ"}
Dim topic As String = "[Code].[T]"
topic = Replace(topic, "[Code]", CStr(code))
topic = Replace(topic, "[T]", T)
Dim item As String = "銘柄名称"
Using client As New DdeClient("RSS", topic)
client.Connect()
Dim buf(1024) As Byte
If client.TryRequest(item, 1, 60000, buf) = 0 Then
count = count + 1
Dim s As String = enc.GetString(buf)
s = s.Substring(0, s.Length - 1)
Debug.WriteLine(count & vbTab & code & vbTab & T & vbTab & s)
End If
End Using
Next
Next
End Sub
リクエスト方式だと遅いですがお手軽に全銘柄取得できます。
とりあえず入門用ってことでAPI直接呼出しとかコールバックとかはまた別のお話。
[楽天RSS] AccessでDDE
Sub Test1()
Dim count As Integer: count = 0
Dim code As Integer: For code = 1300 To 3000
For Each T In Array("T", "Q", "OS", "OJ")
Dim topic As String
topic = "[Code].[T]"
topic = Replace(topic, "[Code]", CStr(code))
topic = Replace(topic, "[T]", T)
On Error Resume Next
Dim ChanNum As Long: ChanNum = Application.DDEInitiate("RSS", topic)
Dim s As String: s = Application.DDERequest(ChanNum, "銘柄名称")
If Err.Number = 0 Then
Application.DDETerminate ChanNum
count = count + 1
Debug.Print count, code, T, s
Exit For
End If
Application.DDETerminate ChanNum
DoEvents
Next
Next
End Sub
[楽天RSS] 銘柄一覧の取得(Excel)
BEAMbitious トレーディング ブログ さんで紹介されてたStockFindを試してみた。
ExcelVBAでお手軽に
Sub 銘柄一覧()
Dim channel As Long: channel = DDEInitiate("RSS", "StockFind")
Dim s As Variant: s = DDERequest(channel, "NULL")
Dim rowIndex As Integer: For rowIndex = LBound(s) To UBound(s)
Dim code As String: code = s(rowIndex, 1)
Dim 名称 As String: 名称 = s(rowIndex, 2)
Dim 業種 As String: 業種 = s(rowIndex, 5)
Dim 市場 As String: 市場 = s(rowIndex, 6)
Debug.Print 業種, 市場, code, 名称
Next
DDETerminate channel
End Sub
すばらしいですね。BEAMbitious の人に感謝。
[楽天RSS] 銘柄一覧の取得(Access)
銘柄一覧の取得 のAccess版
Dim channel As Long: channel = DDEInitiate("RSS", "StockFind")
Dim s As Variant: s = DDERequest(channel, "NULL")
DDETerminate channel
Dim lines() As String: lines = Split(s, vbLf)
Dim rowIndex As Integer: For rowIndex = 1 To UBound(lines)
Dim columns() As String: columns = Split(lines(rowIndex), vbTab)
Dim code As String: code = columns(0)
Dim 名称 As String: 名称 = columns(1)
Dim 業種 As String: 業種 = columns(4)
Dim 市場 As String: 市場 = columns(5)
Debug.Print 業種, 市場, code, 名称
Next
[楽天RSS] DDE(シンプルパターン)
もっとも手抜きにDDEコールバックでRSSから株価を拾ってみる。
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ddeinst As UInteger
Dim pfnCallback = New DdeDelegate(AddressOf DdeCallback)
DdeInitialize(ddeinst, pfnCallback, CBF_SKIP_REGISTRATIONS, 0)
Dim hszServiceName = DdeCreateStringHandle(ddeinst, "RSS", CP_WINANSI)
Dim hszTopicName = DdeCreateStringHandle(ddeinst, "2753.T", CP_WINANSI)
Dim hszItemName = DdeCreateStringHandle(ddeinst, "現在値", CP_WINANSI)
Dim hconv = DdeConnect(ddeinst, hszServiceName, hszTopicName, Nothing)
DdeClientTransaction(Nothing, 0, hconv, hszItemName, CF_TEXT, XTYP_ADVSTART, 9999, Nothing)
End Sub
Public Function DdeCallback(ByVal uType As Integer, ByVal uFmt As Integer, ByVal hConv As IntPtr, ByVal hsz1 As IntPtr, ByVal hsz2 As IntPtr, ByVal hData As IntPtr, ByVal dwData1 As IntPtr, ByVal dwData2 As IntPtr) As IntPtr
If uType = XTYP_ADVDATA Then
Dim data = DdeAccessData(hData, Nothing)
MsgBox(data)
End If
End Function
ほんとは各種ハンドルの解放とかエラー処理が必要ですが、基本これだけ。
あと、API利用のために以下も必要です。
Public Const CBF_SKIP_REGISTRATIONS As Integer = &H80000
Public Const CF_TEXT As Integer = 1
Public Const CP_WINANSI As Integer = 1004
Public Const DDE_FACK As Integer = &H8000
Public Const XTYP_ADVDATA As Integer = &H4010
Public Const XTYP_ADVSTART As Integer = &H1030
Public Const XTYP_ADVSTOP As Integer = &H8040
Public Delegate Function DdeDelegate(ByVal uType As Integer, ByVal uFmt As Integer, ByVal hConv As IntPtr, ByVal hsz1 As IntPtr, ByVal hsz2 As IntPtr, ByVal hData As IntPtr, ByVal dwData1 As IntPtr, ByVal dwData2 As IntPtr) As IntPtr
<DllImport("user32.dll", EntryPoint:="DdeInitialize", CharSet:=CharSet.Ansi)> _
Public Shared Function DdeInitialize(ByRef pidInst As UInteger, ByVal pfnCallback As DdeDelegate, ByVal afCmd As UInteger, ByVal ulRes As UInteger) As UInteger
End Function
<DllImport("user32.dll", EntryPoint:="DdeConnect", CharSet:=CharSet.Ansi)> _
Public Shared Function DdeConnect(ByVal idInst As UInteger, ByVal hszService As IntPtr, ByVal hszTopic As IntPtr, ByVal pCC As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="DdeCreateStringHandle", CharSet:=CharSet.Ansi)> _
Public Shared Function DdeCreateStringHandle(ByVal idInst As UInteger, ByVal psz As String, ByVal iCodePage As Integer) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="DdeAccessData", CharSet:=CharSet.Ansi)> _
Public Shared Function DdeAccessData(ByVal hData As IntPtr, ByRef pcbDataSize As UInteger) As String
End Function
<DllImport("user32.dll", EntryPoint:="DdeClientTransaction", CharSet:=CharSet.Ansi)> _
Public Shared Function DdeClientTransaction(ByVal pData As IntPtr, ByVal cbData As UInteger, ByVal hConv As IntPtr, ByVal hszItem As IntPtr, ByVal wFmt As UInteger, ByVal wType As UInteger, ByVal dwTimeout As UInteger, ByRef pdwResult As UInteger) As IntPtr
End Function
うーむ
マケスピとRSSの自動起動ツールをシェアウェアとして公開しますよ。お小遣いほしいよ。
いきなり有料はアレなんでとりあえず無料でも使えます。
まずはお試しっぽくこっそり公開してみる。→ MSRSS.exe
注意:初期値ではユーザID: MSDEMOが入力されます。 自分のユーザIDとパスワードはちゃんとメモしておいてから起動してください。
・動かなかったらWindowsUpdateで.NET Framework 2.0 を入れてみてください。
・自己責任でお願いします。
・マケスピはVer.7.23で動作確認しました。今後のバージョンでは動かないかもね。
・無料版はユーザIDとパスワードは毎回入力、 開始ボタンも手動です。
・送金するといろいろベンリにする予定です。
なんか機能リクエストとかあれば聞きますよ。





最近のコメント
sippofactory at 07.22
amits at 07.21
sippofactory at 07.21
sippofactory at 07.21
sippofactory at 06.27
匿名 at 06.23
sippofactory at 06.08
sippofactory at 05.26
sippofactory at 05.05