Thank you for your help.
I want to access the specified app of kintone from VBA and reflect the data acquired from it in Excel.
"Error number 438 Object does not support this property or method"
And an error is displayed and the value cannot be reflected.
I would appreciate if you could tell me how to solve it.
Option Explicit
Const DOMAIN_NAME As String = "XXXXXXXX.cybozu.com"
Const BASE_URL As String = "https://" & DOMAIN_NAME & "/k/v1/"
Const APP_ID As String = "XXX"
Const API_TOKEN As String = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Const cellFromRecNumber = "A2"
Const cellFromRecNumber2 = "B4"
Dim strURL As String
Dim objHttpReq As Object
Dim strJSON As String
Dim objJSON As Object
Dim strFromRecNumber As String
Dim strToRecNumber As String
Dim strQuery As String
Dim record As Variant
Dim rep As Variant
Dim js As Object
Dim strFunc As String
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range(cellFromRecNumber)) Is Nothing Then
Exit Sub
Else
Set js = CreateObject("ScriptControl")
js.Language = "JScript"
strFunc = "function jsonParse(s) { return eval('(' + s + ')'); }"
js.AddCode strFunc
strFromRecNumber = Range(cellFromRecNumber)
strQuery = "Userid = """ & strFromRecNumber & """"
strQuery = js.CodeObject.encodeURIComponent(strQuery)
strURL = BASE_URL & "records.json?&app=" & APP_ID & "&query=" & strQuery
Set objHttpReq = CreateObject("MSXML2.XMLHTTP")
objHttpReq.Open "GET", strURL, False
objHttpReq.setRequestHeader "Host", DOMAIN_NAME & ":443"
objHttpReq.setRequestHeader "X-Cybozu-API-Token", API_TOKEN
objHttpReq.setRequestHeader "If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT"
objHttpReq.send (Null)
If objHttpReq.Status <> 200 Then
MsgBox ("Send:Error")
End
End If
strJSON = objHttpReq.responseText
strJSON = Replace(strJSON, """$revision"":", """kintone_revision"":")
Set objJSON = js.CodeObject.jsonParse(strJSON)
For Each record In objJSON.records
Worksheets(1).Range(cellFromRecNumber2).Value = record.Officename.Value
Next record
Set objHttpReq = Nothing
Set js = Nothing
End If
End Sub
Related
I have a function Base64_HMACSHA1 and am getting the error Expected ')'. The full code is:
Public Function Base64_HMACSHA1(ByVal sTextToHash As String, ByVal sSharedSecretKey As String)
Dim asc As Object, enc As Object
Dim TextToHash() As Byte
Dim SharedSecretKey() As Byte
Set asc = CreateObject("System.Text.UTF8Encoding")
Set enc = CreateObject("System.Security.Cryptography.HMACSHA1")
TextToHash = asc.Getbytes_4(sTextToHash)
SharedSecretKey = asc.Getbytes_4(sSharedSecretKey)
enc.Key = SharedSecretKey
Dim bytes() As Byte
bytes = enc.ComputeHash_2((TextToHash))
Base64_HMACSHA1 = EncodeBase64(bytes)
Set asc = Nothing
Set enc = Nothing
End Function
Private Function EncodeBase64(ByRef arrData() As Byte) As String
Dim objXML As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement
Set objXML = New MSXML2.DOMDocument
' byte array to base64
Set objNode = objXML.createElement("b64")
objNode.DataType = "bin.base64"
objNode.nodeTypedValue = arrData
EncodeBase64 = objNode.Text
Set objNode = Nothing
Set objXML = Nothing
End Function
I've tried adding an ) in multiple places but I still get an error. The error message is for Line: 84, Column:51, which is this line: Public Function Base64_HMACSHA1(ByVal sTextToHash As String, ByVal sSharedSecretKey As String)
The code for the url is:
Dim objOAuth : Set objOAuth = New cLibOAuth
objOAuth.ConsumerKey = "0b57d617-7a92-4504-a5e1-25273e3b0384"
objOAuth.ConsumerSecret = "joSPols5B8uyKQqYzkk8uiwHrJ7nq3VwravLnTdJTFXMqSAq0KSBvPVoLETAmUiS"
objOAuth.EndPoint = "https://login.windstream.com/as/token.oauth2"
objOAuth.RequestMethod = OAUTH_REQUEST_METHOD_POST
objOAuth.TimeoutURL = "authenticate.asp"
'objOAuth.Parameters.Add "username", Request.Cookies("username")
'objOAuth.Parameters.Add "password", Request.Cookies("password")
objOAuth.Parameters.Add "oauth_callback", "callback.asp"
objOAuth.Send()
Dim strResponse : strResponse = _
objOAuth.Get_ResponseValue(access_token)
I need to get the page number in order to extract text from that specific page in a .PDF document. I am using Excel VBA function that makes use of the JSObject from the Acrobat Type Library 10.0
Here is the code snippet and the code hicks up on when I am trying to reference the pageNum property from Doc object. I am trying to avoid the AV Layer and use the PD Layer only, so my macro runs in the background only and doesn't invoke Acrobat Application.
Function getTextFromPDF_JS(ByVal strFilename As String) As String
Dim pdDoc As New AcroPDDoc
Dim pdfPage As Acrobat.AcroPDPage
Dim pdfBookmark As Acrobat.AcroPDBookmark
Dim jso As Object
Dim BookMarkRoot As Object
Dim vBookmark As Variant
Dim objSelection As AcroPDTextSelect
Dim objHighlight As AcroHiliteList
Dim currPage As Integer
Dim strText As String
Dim BM_flag As Boolean
Dim count As Integer
Dim word As Variant
strText = ""
If (pdDoc.Open(strFilename)) Then
Set jso = pdDoc.GetJSObject
Set BookMarkRoot = jso.BookMarkRoot
vBookmark = jso.BookMarkRoot.Children
'Add a function call to see if a particular bookmark exists within the .PDF
Set pdfBookmark = CreateObject("AcroExch.PDBookmark")
BM_flag = pdfBookmark.GetByTitle(pdDoc, "Title Page")
If (BM_flag) Then
For i = 0 To UBound(vBookmark)
If vBookmark(i).Name = "Title Page" Then
vBookmark(i).Execute
jso.pageNum
Set pdfPage = pdDoc.AcquirePage(pageNum)
Set objHighlight = New AcroHiliteList
objHighlight.Add 0, 10000 ' Adjust this up if it's not getting all the text on the page
Set objSelection = pdfPage.CreatePageHilite(objHighlight)
If Not objSelection Is Nothing Then
For tCount = 0 To objSelection.GetNumText - 1
strText = strText & objSelection.GetText(tCount)
Next tCount
End If
Exit For
End If
pdDoc.Close
End If
End If
getTextFromPDF_JS = strText
End Function
jso.pageNum = 0; set a page number
pageNo = jso.pageNum; get a page number
edit: 3.3.19
Mmmh, it seems you have to work with AVDoc in order to get the current actual page via jso.pageNum . Also if you work with AVdoc the Acobat window stay hidden in the background. Example:
strFilename = "d:\Test2.pdf"
set avDoc = CreateObject("AcroExch.AVDoc")
If (avDoc.Open(strFilename,"")) Then
Set pdDoc = avDoc.getPDDoc()
Set jso = pdDoc.GetJSObject
pageNo = jso.pageNum
msgbox(pageNo)
end if
I'm trying to fix an old macro working with a function GetData that retrieve the whole page in the response string. (Can't give the real URL here)
Function getDataFor(tva As String) As String
' Early binding, set Tools - Reference - Microsoft XML,v6.0
Dim oDOM As New MSXML2.DOMDocument30
Dim oNodeList As IXMLDOMNodeList
Dim oReq As MSXML2.XMLHTTP
Set oReq = New MSXML2.XMLHTTP
oReq.Open "GET", "https://xxxxxxx.asp?name=" & tva, False
oReq.send
While oReq.readyState <> 4
Wend
Dim response As String
Dim name As String
Dim hasLoginBelspo As String
response = oReq.responseText
Dim token1 As Long
Dim token2 As Long
token1 = InStr(response, "company.name=")
token2 = InStr(response, "company.address=")
On Error GoTo Proceed
name = Mid(response, token1 + 14, token2 - (token1 + 16))
On Error GoTo 0
token1 = InStr(response, "parent.SetLoginInfo")
hasLoginBelspo = Replace(Mid(response, token1 + 28, 5), ",", "")
GoTo Proceed2
Proceed:
name = ""
hasLoginBelspo = ""
Proceed2:
getDataFor = name & "," & hasLoginBelspo
End Function
The concerned page is loaded and the needed data is written between javascript tags:
Here is a copy of what I can find in the source page when I paste the URL in a browser.
<script language="javascript">
var company=new Object();company.number="xxx";company.name="xxx";company.address="xxx";company.zip="xxx";company.city="xxx";parent.SetLoginInfo(company,false,true,"xxx","");
</script>
All the data replaced by xxx is what I need. In the browser, I get it, but with the macro, sometimes those xxx data are empty. It should be because the library used to load the javascript may not be the good one (MSXML2).
Do you have an idea of what I need the change, or what kind of library should I use to be sure the javascript data will be catch?
Thanks a lot
I have a webmethod which will return an object with strings(i.e)str is object and str(0) would be string. str(0)'s length would be 27601. likewise all other array members having the same length.(i.e) str(1)'s length is 27601 also str(2),str(3)......
my webmethod return the exact object. but on the client side javascript doesn't accept the value it immediately fire the error method.
sample code is,
PageMethods.paging("","",pospara,"position_select","stored Procedure",function sucMulti(result){
alert(result);
});
web method is
<WebMethod()> _
<ScriptMethod()> _
Public Shared Function paging(ByVal query As String, ByVal tbl As String, ByVal para() As Object, ByVal spname As String, ByVal cmdtype As String) As Object()
Dim dsrt As New DataSet, dbacc As New dataaccess
If cmdtype = "stored Procedure" Then
dsrt = dbacc.retds1(spname, conn, para)
Else
dsrt = dbacc.retds(query, tbl, conn)
End If
'here dsrt will have 19 rows. so i split them by 8.
Dim no As Integer
Dim rows As Integer = 8
Dim r As Integer
no = Floor(dsrt.Tables(0).Rows.Count / rows)
If dsrt.Tables(0).Rows.Count < rows Then
r = 0
Else
r = dsrt.Tables(0).Rows.Count Mod rows
End If
Dim start As Integer = 0
Dim last As Integer = 7
Dim str(0) As Object
Dim dv As New DataView
dv = dsrt.Tables(0).DefaultView
If r <> 0 Then
no += 1
End If
If no >= 1 Then
ReDim str(no - 1)
For i As Integer = 1 To no
Dim ds As New DataSet
Dim dt As New DataTable
dt = dsrt.Tables(0).Clone
dt.Rows.Clear()
For j As Integer = start To last
dt.ImportRow(dsrt.Tables(0).Rows(j))
Next
start = (rows * i)
If r <> 0 And i = no - 1 Then
last = last + r
Else
last = start + 7
End If
ds.Tables.Add(dt)
str(i - 1) = ds.GetXml
Next
Else
str(0) = dsrt.GetXml
End If
Dim len As Integer = str(0).ToString.Length
Return str
End Function
everything goes fine . str will contain 4 rows, each row would have a string with 27601 length. but javascript doesn't alert the result. why?
I found a solution that to increase the jason max length by the following.
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="5000"/>
</webServices>
</scripting>
I put the above code inside the tag of web Config file.It works but it gives tooltip error message on the first tag. any suggestions to correct it?
the error message is,
"the element 'configuration' in namespace 'http://schemas.microsoft.com/.NetConfiguration/v2.0' has invalid child element 'system.we.extensions' in namespace 'http://schemas.microsoft.com/.NetConfiguration/v2.0'. List of possible elements expected: 'system.net' in namespace 'http://schemas.microsoft.com/.NetConfiguration/v2.0'"
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim cons, query As String
Dim con As OdbcConnection
Dim adpt As OdbcDataAdapter
'Dim num As Integer
cons = "dsn=Courier; UID=Courier; PWD=123;"
con = New OdbcConnection(cons)
con.Open()
query = "select Name from EMPLOYEE where EMPLOYEE_ID=" + DropDownList1.SelectedValue
Dim ds As DataSet
adpt = New OdbcDataAdapter(query, con)
ds = New DataSet
adpt.Fill(ds, "Courier")
' TextBox1.Text = ds
con.Close()
End Sub
I want to display the name of the employee in Textbox whoos ID is specified in query, what can I do for that?
You should use DataRow but to answer your question, try this.
TextBox1.Text = ds.Tables(0).Rows(0)("Name").ToString()
Since you only want one value back you should skip the dataset and adapter altogether.
query = "select Name from EMPLOYEE where EMPLOYEE_ID=" + DropDownList1.SelectedValue
Dim TempName As String = query.ExecuteScalar
TextBox1.Text = TempName
ExecuteScalar returns the first cell of the first row, that's all you need.
You should read about parameters as well.