How to send a request to a webserver in VBA?

  • Thread starter Thread starter Amit
  • Start date Start date
A

Amit

Hello again,

Is it possible to send a request to a web-server or web-service in VBA?
I need to run a command on a server to get information off its
database? Does anybody know how and if there is any resource on the
web?

Thanks in advnce,
AK
 
Alex Thank you so much. It was a great code and works just fine for me.
However, since I'm new to VBA and used to call try and catch in C++. Is
there any method or way to catch unexpected errors such as a
connectionless scenario or if the server returns an error code i.e page
not found and ...?


Your help is appreicated greatly.
Amit.
 
Hi,
in VBA you can do it like below:

Function GetRateCBR(dDate As Date)

On Error GoTo GetRateCBR_Error

'proc code starts here

GetRateCBR_End:
On Error Resume Next
Exit Function

GetRateCBR_Error:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ")
in procedure GetRateCBR of Module Module"
Resume GetRateCBR_End
End Select

End Function

actually - there is a very good addin to insert error handler staff in VBA
proc, see www.mztools.com


--
Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
 
Alex,

Thank you. I am going to try it but meantime I need to ask you one more
question!
The code I'm using insert all the request information into Excel grid
directly but
How can I place them into an array first?

I want to use a progress bar so I need to read each row from an array
line by line to be able to use the progress bar. Any advice on this?

Once again thanks for your wonderful help.

AK
 
Alex once again thanks for your concern and help. below is the code
that you gave me and i'm using it in order to retrieve some informatoin
off a web server. As you know better following code will place all
information in cell A7 and following cells.
Now, since I need to create a progress bar I think that the best way
would be inserting all coming informatin into an array first. Then
afterwards, I will read the information from the array and will
populate the sheet then I can use a progress bar based on each row
being filled.

1) My question is how can I have this code to put information in an
array instead of sheet first?

2) Also, one more thing. I found a demo (VBA) code that had a combo-box
on its chart! how this could be implemented?

Thank you so much.
AK



Dim strRq1 As String
Dim strRq2 As String
Dim strRq3 As String


On Error Resume Next

'Clean up the page
ActiveWindow.ActiveSheet.UsedRange.Clear

'Populate the sheet from A7 cell on
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;" & strRq1 & strRq2 & strRq3, _
Destination:=Range("A7"))
.BackgroundQuery = True
.TablesOnlyFromHTML = True
.Refresh BackgroundQuery:=False
.SaveData = True
End With
 
Back
Top