Passing response value between thisworkbook and standard module

stapuff

Well-known Member
Joined
Feb 19, 2004
Messages
1,126
I am doing a simple xml webservice macro call to determine the users security clearance....which returns a GetRestWebServiceValue=true or GetRestWebServiceValue=false response. This call is being done at the thisworkbook level using a public sub workbook_open() macro. I can step through the macro and see all works as it should, but the true or false is not getting passed to the standard module Public GetRestWebServiceValue As String.

As soon as the workbook_open() hits a exit sub or end sub the value is lost.

Any suggestions would be greatly appreciated.


Code:
Public Sub Workbook_Open()

Dim url As String
User = Environ("username")
url = "http://ws.yahoo.com/ws/secured/authorization/" & User
 
On Error GoTo Err_SuperTrap
    GetRestWebServiceValue = ""
  
    Dim xmlhttp
    Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
    Call xmlhttp.Open("GET", url, False)
    
    Call xmlhttp.send
    
    Dim xmldoc As DOMDocument
    
    Set xmldoc = CreateObject("Microsoft.XMLDOM")
    xmldoc.async = False
    
    xmldoc.LoadXML (xmlhttp.responseText)
        
    GetRestWebServiceValue = xmldoc.Text

MsgBox GetRestWebServiceValue
Exit_SuperTrap:
Exit Sub

Err_SuperTrap:

    If Err.Number <> -2146697211 Then
        MsgBox Err.Description
    End If
    GetRestWebServiceValue = "Intranet Server Down"

End Sub

code in a standard module

Code:
Public GetRestWebServiceValue As String
Dim adoCN As ADODB.Connection
Dim adoRS As ADODB.Recordset
Dim ReturnField As String
Dim strSQL As String
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I am an idiot.


The macro needs to be in a standard module and the call to run it in the workbook open event.
Code:
Private Sub Workbook_Open()
Run "security_check"
End Sub


Code:
Public Sub security_check() 
Dim url As String
User = Environ("username")
url = "http://ws.yahoo.com/ws/secured/authorization/" & User
 
On Error GoTo Err_SuperTrap
    GetRestWebServiceValue = ""
  
    Dim xmlhttp
    Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
    Call xmlhttp.Open("GET", url, False)
    
    Call xmlhttp.send
    
    Dim xmldoc As DOMDocument
    
    Set xmldoc = CreateObject("Microsoft.XMLDOM")
    xmldoc.async = False
    
    xmldoc.LoadXML (xmlhttp.responseText)
        
    GetRestWebServiceValue = xmldoc.Text

MsgBox GetRestWebServiceValue
Exit_SuperTrap:
Exit Sub

Err_SuperTrap:

    If Err.Number <> -2146697211 Then
        MsgBox Err.Description
    End If
    GetRestWebServiceValue = "Intranet Server Down"
end sub
 
Upvote 0

Forum statistics

Threads
1,216,109
Messages
6,128,883
Members
449,477
Latest member
panjongshing

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top