Hello Team,
We are trying to use cookies in a UserForm. We have a button in user access form, it should fetch few details in the same window the moment you clicked on the button. Cookies are mandatory to use. can someone help this. Please find the below code we are using
[FONT="]Public Sub StatusAction()[/FONT]
[FONT="] [/FONT]
[FONT="]On Error GoTo Error_Handler[/FONT]
[FONT="] [/FONT]
[FONT="] If ActiveWorkbook.Saved Then IsTemplateSaved = True[/FONT]
[FONT="] GlobalSettings.getActionName = getButtonActionStatus[/FONT]
[FONT="] If IsDestinationReachable = False Then[/FONT]
[FONT="] ShowServerNotReachableMsg[/FONT]
[FONT="] Exit Sub[/FONT]
[FONT="] End If[/FONT]
[FONT="] [/FONT]
[FONT="] If ExcelHandler Is Nothing Then[/FONT]
[FONT="] Set ExcelHandler = New ExcelHandler[/FONT]
[FONT="] End If[/FONT]
[FONT="] [/FONT]
[FONT="] Dim UniqueID As String[/FONT]
[FONT="] UniqueID = SystemFunctions.GenerateUniqueId(gstrSTPAccount)[/FONT]
[FONT="] [/FONT]
[FONT="] Dim FinalStr As String[/FONT]
[FONT="] [/FONT]
[FONT="] FinalStr = Replace(UniqueID, Chr(13), " ", , , vbTextCompare)[/FONT]
[FONT="] FinalStr = Replace(FinalStr, Chr(10), " ", , , vbTextCompare)[/FONT]
[FONT="] [/FONT]
[FONT="] Dim overridefolder As String[/FONT]
[FONT="] overridefolder = ActiveWorkbook.Worksheets.Item("SWSHEETMETA").Range("B1")[/FONT]
[FONT="] [/FONT]
[FONT="] Dim overridePath As String[/FONT]
[FONT="] overridePath = doSubmit.ResolvePath(overridefolder, GlobalSettings.gstrSTPService, GlobalSettings.gstrSTPAccount)[/FONT]
[FONT="] [/FONT]
[FONT="] Dim selectedLocale As String[/FONT]
[FONT="] selectedLocale = ActiveWorkbook.Worksheets.Item("SWSHEETMETA").Range("F1")[/FONT]
[FONT="] Dim Cookies As String[/FONT]
[FONT="] Cookies = ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("P1")[/FONT]
[FONT="] Dim header As String[/FONT]
[FONT="] [/FONT]
[FONT="] header = "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)" & vbCrLf & _[/FONT]
[FONT="] "authentication:" & gstrSTPAuthentication & vbCrLf & _[/FONT]
[FONT="] "Cookie:" & Cookies & vbCrLf & _[/FONT]
[FONT="] "sppmBaseUrl:" & gstrSTPServerIP & vbCrLf & _[/FONT]
[FONT="] "username:" & gstrSTPAccount & vbCrLf & _[/FONT]
[FONT="] "worksheetPkId:" & gstrSTPWorksheetID & vbCrLf & _[/FONT]
[FONT="] "overrideFolder:" & overridePath & vbCrLf & _[/FONT]
[FONT="] "selectedLocale:" & selectedLocale & vbCrLf & _[/FONT]
[FONT="] "uniqueid:" & FinalStr & vbCrLf & _[/FONT]
[FONT="] "Accept-Encoding:" & "gzip, deflate" & vbCrLf & _[/FONT]
[FONT="] "Accept:" & "*/*" & vbCrLf & _[/FONT]
[FONT="] "Accept-Language:" & "en-us" & vbCrLf & _[/FONT]
[FONT="] "account:" & gstrSTPAccount & vbCrLf & _[/FONT]
[FONT="] "ContentType:" & "application/x-www-form-urlencoded" & vbCrLf & _[/FONT]
[FONT="] "Connection:" & "Keep-Alive" & vbCrLf & _[/FONT]
[FONT="] "Host:" & Replace(gstrSTPService, "-", ":") & vbCrLf & _[/FONT]
[FONT="] "Method:" & "POST" & vbCrLf[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="] Dim sURL As String[/FONT]
[FONT="] 'sURL = gstrSTPServerIP & "amb/webMyTemplate?" & "selectedLocaleAmb=" & locale[/FONT]
[FONT="] 'sURL = gstrSTPServerIP & gEtMyTemplatesUrl & "?selectedLocaleAmb=" & GlobalSettings.gTempLocale 'locale[/FONT]
[FONT="] Dim TemplateType As String[/FONT]
[FONT="] If ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("B7").Value = "OPPORTUNITY_TEMPLATE" Then[/FONT]
[FONT="] TemplateType = "OPPORTUNITY_TEMPLATE"[/FONT]
[FONT="] Else[/FONT]
[FONT="] TemplateType = "TEMPLATE"[/FONT]
[FONT="] End If[/FONT]
[FONT="] [/FONT]
[FONT="] Dim statusurl As Long[/FONT]
[FONT="] Dim gmtconv As Date[/FONT]
[FONT="] Dim milli As Variant[/FONT]
[FONT="] [/FONT]
[FONT="] gmtconv = ConvertLocalToGMT(Now)[/FONT]
[FONT="] milli = MillSec("1/1/1970 0:00AM", gmtconv)[/FONT]
[FONT="] [/FONT]
[FONT="] If InStr(ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("B14").Value, "/snop/") > 0 Then[/FONT]
[FONT="] sURL = gstrSTPServerIP & "snop/index.html?" & "&tmp=" & milli & "&actionname=status&" & GetFolderListStatus(ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("I17"), "xml") & "&worksheetPkId=" & gstrSTPWorksheetID & "&selectedLocaleAmb=" & selectedLocale & "&template_type=" & TemplateType & "&overrideFolder=" & Replace(overridePath, " ", "|") & "#/status" & "?hide=7&"[/FONT]
[FONT="] UserForm1.WebBrowser1.Navigate2 sURL, , , , header[/FONT]
[FONT="] SetFormOpacity UserForm1, 0[/FONT]
[FONT="] UserForm1.Show[/FONT]
[FONT="] Else[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="] If InStr(ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("B14").Value, "/planstreaming/") > 0 Then[/FONT]
[FONT="] 'sURL = gstrSTPServerIP & "planstreaming/index.html?actionname=status&" & GetFolderListStatus(ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("I17"), "xml") & "&worksheetPkId=" & gstrSTPWorksheetID & "&selectedLocaleAmb=" & selectedLocale & "&template_type=" & TemplateType & "&overrideFolder=" & Replace(overridePath, " ", "|") & "#/status" & "?hide=7"[/FONT]
[FONT="] 'sURL = gstrSTPServerIP & "planstreaming/index.html?" & "actionname=status" & "&tmp=" & milli & "#/status" & "?hide=7&" & GetFolderListStatus(ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("I17"), "xml") & "&worksheetPkId=" & gstrSTPWorksheetID & "&selectedLocaleAmb=" & selectedLocale & "&template_type=" & TemplateType & "&actionname=status" & "&overrideFolder=" & Replace(overridePath, " ", "|") & "&htmp=" & milli[/FONT]
[FONT="] sURL = gstrSTPServerIP & "planstreaming/index.html?" & "&tmp=" & milli & "&actionname=status&" & GetFolderListStatus(ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("I17"), "xml") & "&worksheetPkId=" & gstrSTPWorksheetID & "&selectedLocaleAmb=" & selectedLocale & "&template_type=" & TemplateType & "&overrideFolder=" & Replace(overridePath, " ", "|") & "#/status" & "?hide=7&"[/FONT]
[FONT="] UserForm1.WebBrowser1.Navigate2 sURL, , , , header[/FONT]
[FONT="] SetFormOpacity UserForm1, 0[/FONT]
[FONT="] UserForm1.Show[/FONT]
[FONT="] Else[/FONT]
[FONT="] sURL = gstrSTPServerIP & "amb/vbastatus" & "?selectedLocaleAmb=" & GlobalSettings.gTempLocale & "&" & "template_type=" & TemplateType[/FONT]
[FONT="] UserForm1.WebBrowser1.Navigate2 sURL, , , , header[/FONT]
[FONT="] SetFormOpacity UserForm1, 0[/FONT]
[FONT="] UserForm1.Show[/FONT]
[FONT="] End If[/FONT]
[FONT="] End If[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="] GlobalSettings.getActionName = ""[/FONT]
[FONT="]Exit Sub[/FONT]
[FONT="] [/FONT]
[FONT="]Error_Handler:[/FONT]
[FONT="] [/FONT]
[FONT="] Dim stra As String[/FONT]
[FONT="] stra = "Error in StatusAction function of Actions"[/FONT]
[FONT="] Call ErrorHandler.ErrorHandler(stra)[/FONT]
[FONT="] GlobalSettings.getActionName = ""[/FONT]
[FONT="] [/FONT]
[FONT="]End Sub[/FONT]
We are trying to use cookies in a UserForm. We have a button in user access form, it should fetch few details in the same window the moment you clicked on the button. Cookies are mandatory to use. can someone help this. Please find the below code we are using
[FONT="]Public Sub StatusAction()[/FONT]
[FONT="] [/FONT]
[FONT="]On Error GoTo Error_Handler[/FONT]
[FONT="] [/FONT]
[FONT="] If ActiveWorkbook.Saved Then IsTemplateSaved = True[/FONT]
[FONT="] GlobalSettings.getActionName = getButtonActionStatus[/FONT]
[FONT="] If IsDestinationReachable = False Then[/FONT]
[FONT="] ShowServerNotReachableMsg[/FONT]
[FONT="] Exit Sub[/FONT]
[FONT="] End If[/FONT]
[FONT="] [/FONT]
[FONT="] If ExcelHandler Is Nothing Then[/FONT]
[FONT="] Set ExcelHandler = New ExcelHandler[/FONT]
[FONT="] End If[/FONT]
[FONT="] [/FONT]
[FONT="] Dim UniqueID As String[/FONT]
[FONT="] UniqueID = SystemFunctions.GenerateUniqueId(gstrSTPAccount)[/FONT]
[FONT="] [/FONT]
[FONT="] Dim FinalStr As String[/FONT]
[FONT="] [/FONT]
[FONT="] FinalStr = Replace(UniqueID, Chr(13), " ", , , vbTextCompare)[/FONT]
[FONT="] FinalStr = Replace(FinalStr, Chr(10), " ", , , vbTextCompare)[/FONT]
[FONT="] [/FONT]
[FONT="] Dim overridefolder As String[/FONT]
[FONT="] overridefolder = ActiveWorkbook.Worksheets.Item("SWSHEETMETA").Range("B1")[/FONT]
[FONT="] [/FONT]
[FONT="] Dim overridePath As String[/FONT]
[FONT="] overridePath = doSubmit.ResolvePath(overridefolder, GlobalSettings.gstrSTPService, GlobalSettings.gstrSTPAccount)[/FONT]
[FONT="] [/FONT]
[FONT="] Dim selectedLocale As String[/FONT]
[FONT="] selectedLocale = ActiveWorkbook.Worksheets.Item("SWSHEETMETA").Range("F1")[/FONT]
[FONT="] Dim Cookies As String[/FONT]
[FONT="] Cookies = ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("P1")[/FONT]
[FONT="] Dim header As String[/FONT]
[FONT="] [/FONT]
[FONT="] header = "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)" & vbCrLf & _[/FONT]
[FONT="] "authentication:" & gstrSTPAuthentication & vbCrLf & _[/FONT]
[FONT="] "Cookie:" & Cookies & vbCrLf & _[/FONT]
[FONT="] "sppmBaseUrl:" & gstrSTPServerIP & vbCrLf & _[/FONT]
[FONT="] "username:" & gstrSTPAccount & vbCrLf & _[/FONT]
[FONT="] "worksheetPkId:" & gstrSTPWorksheetID & vbCrLf & _[/FONT]
[FONT="] "overrideFolder:" & overridePath & vbCrLf & _[/FONT]
[FONT="] "selectedLocale:" & selectedLocale & vbCrLf & _[/FONT]
[FONT="] "uniqueid:" & FinalStr & vbCrLf & _[/FONT]
[FONT="] "Accept-Encoding:" & "gzip, deflate" & vbCrLf & _[/FONT]
[FONT="] "Accept:" & "*/*" & vbCrLf & _[/FONT]
[FONT="] "Accept-Language:" & "en-us" & vbCrLf & _[/FONT]
[FONT="] "account:" & gstrSTPAccount & vbCrLf & _[/FONT]
[FONT="] "ContentType:" & "application/x-www-form-urlencoded" & vbCrLf & _[/FONT]
[FONT="] "Connection:" & "Keep-Alive" & vbCrLf & _[/FONT]
[FONT="] "Host:" & Replace(gstrSTPService, "-", ":") & vbCrLf & _[/FONT]
[FONT="] "Method:" & "POST" & vbCrLf[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="] Dim sURL As String[/FONT]
[FONT="] 'sURL = gstrSTPServerIP & "amb/webMyTemplate?" & "selectedLocaleAmb=" & locale[/FONT]
[FONT="] 'sURL = gstrSTPServerIP & gEtMyTemplatesUrl & "?selectedLocaleAmb=" & GlobalSettings.gTempLocale 'locale[/FONT]
[FONT="] Dim TemplateType As String[/FONT]
[FONT="] If ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("B7").Value = "OPPORTUNITY_TEMPLATE" Then[/FONT]
[FONT="] TemplateType = "OPPORTUNITY_TEMPLATE"[/FONT]
[FONT="] Else[/FONT]
[FONT="] TemplateType = "TEMPLATE"[/FONT]
[FONT="] End If[/FONT]
[FONT="] [/FONT]
[FONT="] Dim statusurl As Long[/FONT]
[FONT="] Dim gmtconv As Date[/FONT]
[FONT="] Dim milli As Variant[/FONT]
[FONT="] [/FONT]
[FONT="] gmtconv = ConvertLocalToGMT(Now)[/FONT]
[FONT="] milli = MillSec("1/1/1970 0:00AM", gmtconv)[/FONT]
[FONT="] [/FONT]
[FONT="] If InStr(ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("B14").Value, "/snop/") > 0 Then[/FONT]
[FONT="] sURL = gstrSTPServerIP & "snop/index.html?" & "&tmp=" & milli & "&actionname=status&" & GetFolderListStatus(ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("I17"), "xml") & "&worksheetPkId=" & gstrSTPWorksheetID & "&selectedLocaleAmb=" & selectedLocale & "&template_type=" & TemplateType & "&overrideFolder=" & Replace(overridePath, " ", "|") & "#/status" & "?hide=7&"[/FONT]
[FONT="] UserForm1.WebBrowser1.Navigate2 sURL, , , , header[/FONT]
[FONT="] SetFormOpacity UserForm1, 0[/FONT]
[FONT="] UserForm1.Show[/FONT]
[FONT="] Else[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="] If InStr(ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("B14").Value, "/planstreaming/") > 0 Then[/FONT]
[FONT="] 'sURL = gstrSTPServerIP & "planstreaming/index.html?actionname=status&" & GetFolderListStatus(ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("I17"), "xml") & "&worksheetPkId=" & gstrSTPWorksheetID & "&selectedLocaleAmb=" & selectedLocale & "&template_type=" & TemplateType & "&overrideFolder=" & Replace(overridePath, " ", "|") & "#/status" & "?hide=7"[/FONT]
[FONT="] 'sURL = gstrSTPServerIP & "planstreaming/index.html?" & "actionname=status" & "&tmp=" & milli & "#/status" & "?hide=7&" & GetFolderListStatus(ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("I17"), "xml") & "&worksheetPkId=" & gstrSTPWorksheetID & "&selectedLocaleAmb=" & selectedLocale & "&template_type=" & TemplateType & "&actionname=status" & "&overrideFolder=" & Replace(overridePath, " ", "|") & "&htmp=" & milli[/FONT]
[FONT="] sURL = gstrSTPServerIP & "planstreaming/index.html?" & "&tmp=" & milli & "&actionname=status&" & GetFolderListStatus(ActiveWorkbook.Worksheets(AmbassadorSheetName).Range("I17"), "xml") & "&worksheetPkId=" & gstrSTPWorksheetID & "&selectedLocaleAmb=" & selectedLocale & "&template_type=" & TemplateType & "&overrideFolder=" & Replace(overridePath, " ", "|") & "#/status" & "?hide=7&"[/FONT]
[FONT="] UserForm1.WebBrowser1.Navigate2 sURL, , , , header[/FONT]
[FONT="] SetFormOpacity UserForm1, 0[/FONT]
[FONT="] UserForm1.Show[/FONT]
[FONT="] Else[/FONT]
[FONT="] sURL = gstrSTPServerIP & "amb/vbastatus" & "?selectedLocaleAmb=" & GlobalSettings.gTempLocale & "&" & "template_type=" & TemplateType[/FONT]
[FONT="] UserForm1.WebBrowser1.Navigate2 sURL, , , , header[/FONT]
[FONT="] SetFormOpacity UserForm1, 0[/FONT]
[FONT="] UserForm1.Show[/FONT]
[FONT="] End If[/FONT]
[FONT="] End If[/FONT]
[FONT="] [/FONT]
[FONT="] [/FONT]
[FONT="] GlobalSettings.getActionName = ""[/FONT]
[FONT="]Exit Sub[/FONT]
[FONT="] [/FONT]
[FONT="]Error_Handler:[/FONT]
[FONT="] [/FONT]
[FONT="] Dim stra As String[/FONT]
[FONT="] stra = "Error in StatusAction function of Actions"[/FONT]
[FONT="] Call ErrorHandler.ErrorHandler(stra)[/FONT]
[FONT="] GlobalSettings.getActionName = ""[/FONT]
[FONT="] [/FONT]
[FONT="]End Sub[/FONT]