Arrow43050
New Member
- Joined
- Jun 11, 2019
- Messages
- 4
I am trying to use random.org to get a few random numbers (I am not super advanced in writing in VBA so I am just going to get them one at a time). I saw sample code that was written in a reply to a post in 2012 on this site. I tried using the code but I got an error Run-time error '429' ActiveX component can't create object. I admittedly know nothing about objects but was just copying the code that I saw. Can someone please let me know how I can get this to work? I have not finished the code but was just testing that I'd be able to send out the request and get a number back and it failed. I can tell you that if I copy and paste the URL I have below, it does give me one random number between 1 and 6 on random.org's webpage. So I know that isn't the problem at least. What I have so far is:
The original code posted by the person who replied in 2012 was as follows. I'm not sure if objects or anything way beyond my knowledge level has changed or if I just messed something up.
Rich (BB code):
Sub BattingRoll()
Dim dsXMLObj As Object
Dim dsURL As String
Dim dsRespText
Dim I As Long
Dim dsBattingCol As Long
Dim dsBattingTot As Long
dsURL = "http://www.random.org/integers/?num=1&min=1&max=6&col=1&base=10&format=plain&rnd=plain"
Set dsXMLObj = CreateObject("MSXML2.ServerXMLHTTP.4.0")
With dsXMLObj
.Open "GET", dsURL, False
.send
dsRespText = .responseText
dsBattingCol = Val(Split(dsRespText, Chr(10)))
End With
End Sub
The original code posted by the person who replied in 2012 was as follows. I'm not sure if objects or anything way beyond my knowledge level has changed or if I just messed something up.
Rich (BB code):
Option Explicit
Function GetRndNos(NUM As Long, MIN As Long, MAX As Long) As Variant
Dim objXMLHTTP As Object
Dim strURL As String
Dim strResp
Dim I As Long
strURL = "http://www.random.org/integers/"
strURL = strURL & "?num=" & NUM & "&min=" & MIN & "&max=" & MAX & "&col=1&base=10&format=plain&rnd=plain"
Debug.Print strURL
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.4.0")
With objXMLHTTP
.Open "GET", strURL, False
.send
strResp = .responseText
GetRndNos = Split(strResp, Chr(10))
End With
Set objXMLHTTP = Nothing
End Function
Sub test()
Range("A1:A100").Value = Application.Transpose(GetRndNos(100, 1, 100))
End Sub