ken_nogi/XVBA/稟議集計/vba-files/Module/Module2.bas
Kenichiro NOGI 4f9593b26f 2025-12-13
2025-12-13 18:12:03 +09:00

58 lines
1.8 KiB
QBasic
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Attribute VB_Name = "Module2"
Option Explicit
'******************************************************************************
'REST API呼出処理
' method GetかPOSTか
' url REST APIのURL
' urlParam リクエストパラメータオプション
' headers ヘッダオプション
Function callRestApi(Byval method As String, Byval url As String, Optional Byval urlParam As String = "", Optional Byval headers As Dictionary = Null, Optional Byval body As Dictionary = Null) As Object
'HTTPリクエストのオブジェクトを定義
Dim objHTTP As Object
Set objHTTP = New XMLHTTP60
'HTTPリクエストの接続先を設定
objHTTP.Open method, url & urlParam, False
'リクエストヘッダーを設定複数ある場合はsetRequestHeaderを複数書けば良いのだ
Dim i As Long
For i = 0 To headers.count - 1
objHTTP.setRequestHeader headers.keys(i), headers.items(i)
Next i
'リクエスト送信
objHTTP.send JsonConverter.ConvertToJson(body)
Do While objHTTP.readyState < 4
DoEvents
Loop
'レスポンスの文字列objHTTP.responseTextをJsonに変換して返却
Set callRestApi = JsonConverter.ParseJson(objHTTP.responseText)
End Function
'文字列の日付を変換
Function 日付変換(Byval dateVal As String) As Variant
If dateVal = "1899-12-30T00:00:00" Then
日付変換 = ""
Elseif dateVal = "" Then
日付変換 = ""
Else
dateVal = Replace(dateVal, ".000Z", "")
日付変換 = CDate(Replace(dateVal, "T", " "))
End If
End Function
'シートの存在確認
Function シート確認(SheetName As String, Optional wb As Excel.Workbook) As Boolean
Dim Sh As Excel.Worksheet
If wb Is Nothing Then Set wb = ThisWorkbook
On Error Resume Next
Set Sh = wb.Sheets(SheetName)
On Error Goto 0
シート確認 = Not Sh Is Nothing
End Function