テスト26
Private Sub Workbook_Open()
'祝休日からの営業日判定
'--------------------
'事前に参照設定を行う
'Microsoft XML, v3.0
'---------------------
'https://www.apibank.jp/ApiBank/api/detail?api_no=599&api_type=Iを参照
'祝日判定WebAPI
'内閣府のwebを元に祝日チェック(日本特有の官公庁や東証の休日にも対応)を行うwebAPI
'-----------------------
Dim D As Variant '日付用
Dim apiUrL As String 'apiのURL
Dim apiUrL2 As String 'apiのURL
Dim day As Variant
Dim HttpReq As Object 'Httpリクエストオブジェクト用
Dim i As Long 'カウンタ
Dim j As Long '営業日
Dim k As Long '通常日数
Application.ScreenUpdating = False
On Error GoTo ErExit
apiUrL = "http://s-proj.com/utils/checkHoliday.php?kind=h&date="
D = Replace(Date, "/", "")
i = 1
Set HttpReq = CreateObject("MSXML2.XMLHTTP")
apiUrL2 = apiUrL
D = Date
k = 0
'-----------------------------------------
For i = 1 To 21
D = Replace(D, "/", "")
apiUrL2 = apiUrL & D
HttpReq.Open "GET", apiUrL2, False
HttpReq.Send (Null)
'戻り値(祝休日の場合holiday、それ以外はelseを返す)
If HttpReq.responseText = "else" Then
'営業日計算で指定の日数に達した条件ごとに入力
If j = 1 Then
ThisWorkbook.Sheets("Sheet7").Cells(4, 2).Value = Format(D, "0000/00/00")
ElseIf j = 5 Then
ThisWorkbook.Sheets("Sheet7").Cells(5, 2).Value = Format(D, "0000/00/00")
ElseIf j = 10 Then
ThisWorkbook.Sheets("Sheet7").Cells(6, 2).Value = Format(D, "0000/00/00")
End If
j = j + 1 '営業日日数加算
k = k + 1 '通常日数加算
Else
'通常日数加算
k = k + 1
End If
D = Date + k
If k = 21 Then
ThisWorkbook.Sheets("Sheet7").Cells(7, 2).Value = D
End If
Next i
'-----------------------------------------
Set HttpReq = Nothing
Application.ScreenUpdating = True
Exit Sub
'----------------------
ErExit:
MsgBox "サーバーに接続できなかったので、手入力でお願いします。", vbCritical
Set HttpReq = Nothing
Application.ScreenUpdating = True
End Sub
Author And Source
この問題について(テスト26), 我々は、より多くの情報をここで見つけました https://qiita.com/tqr65rs/items/0ccc7d854ffa391a0639著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .