2025年2月11日火曜日

aaaaaa

    ' ++++++++++++++++++++++++++++++
    'テキストインポート
    Dim sKEY    As String
    Dim iPos    As Integer
    
    sKEY = "EXEC"
    sKEY = Worksheets(L_SHEET).Cells(1, 2)
    Open sG_SRC For Input As #1
    Open sG_SRC & ".csv" For Output As #2
    i = G_RowSta
    iCnt = 0
    Do Until EOF(1)
        Line Input #1, sRec
        wsM.Cells(i, G_ColSta1) = sRec
        wsM.Cells(i, G_ColSta2) = sRec
        iCnt = iCnt + 1
        i = i + 1
        '
        iPos = InStr(1, sRec, sKEY)
        If iPos > 0 Then
            'Print #2, iCnt & "," & iPos & "," & Right(sRec, iPos - 1)
            
            sRec = Replace(sRec, " ", ",")
            '           sRec = Replace(sRec, " ", ",", iPos + Len(sKEY) + 3)
            Print #2, iCnt & "," & iPos & "," & Mid(sRec, iPos)
        End If
    Loop
    Close #1
    Close #2
    ' ++++++++++++++++++++++++++++++

2024年12月6日金曜日

teamp

 ・Loopにて表作成を選択する



・excel表からの取込

excle表全体を選択コピーして作成したLoop表の左上をクリックして貼付ける


・ブラウザから操作した方が良い。


・Loop表を必要に応じて共同編集して意見をまとめ上げる



・excelへのExport

その他[・・・]メニューからボタン[excelへのExport]押下


・Loopファイルは、OneDriveの[ファイル]フォルダ配下にLoop投稿単位に作成される


・ダウンロードして

excelファイルを提出物として整形する

 効率よくするために

 ALT + OA で表パターン選択

 目盛線を外す

 行固定

 印刷設定する(

行固定、ヘッダとフッタ、列調整、サイズ調整)

2024年6月30日日曜日

L67

 Option Explicit
'
    Public Const G_MSG_TIL  As String = "L6L7"
    
    Public Const L6_SHEET    As String = "L6"
    Public Const L7_SHEET    As String = "L7"
    Public Const L6T_SHEET   As String = "L6T"
    Public Const L7T_SHEET   As String = "L7T"
   
' メイン処理
'
Sub Main()

    Application.MacroOptions Macro:="Main", ShortcutKey:="j"
    
    Dim wsL6   As Worksheet: Set wsL6 = Worksheets(L6_SHEET)
    Dim wsL7   As Worksheet: Set wsL7 = Worksheets(L7_SHEET)
    Dim wsL6T  As Worksheet: Set wsL6T = Worksheets(L6T_SHEET)
    Dim wsL7T  As Worksheet: Set wsL7T = Worksheets(L7T_SHEET)
    
    Dim iEndRowL6  As Long
    Dim iEndRowL7  As Long
    ' -------------------------------
    ' 初期処理
    ' -------------------------------
    iEndRowL6 = wsL6.Cells(Rows.Count, 2).End(xlUp).Row
    iEndRowL7 = wsL7.Cells(Rows.Count, 2).End(xlUp).Row

    ' -------------------------------
    ' 主処理
    ' -------------------------------
    Dim i    As Long: i = 1
    Dim j    As Long: j = 3
    Dim iPos As Long: iPos = 1
    
    Dim iStaRowL6 As Long: iStaRowL6 = 2
    '-- L6 -> L6T --------------------------------------
    wsL6.Activate
    For j = 1 To 43
        wsL6T.Cells(1, j + 2) = j
        wsL6T.Cells(1, j + 2).Interior.ColorIndex = 8
    Next j
    For i = iStaRowL6 To iEndRowL6
        For j = 1 To 6
            If j = 1 Then
                wsL6T.Cells(i, 1) = wsL6.Cells(i, 2)
            End If
            iPos = Trim(wsL6.Cells(i, j + 2))
            wsL6T.Cells(i, iPos + 2) = "〇"
            If Is_Lucky_Num(L6_SHEET, iPos) = True Then
                wsL6T.Cells(i, iPos + 2) = "★"
            End If
        Next j
    Next i
    Call Format_T(L6T_SHEET, iEndRowL6, 44)
    '最終列をシャドウ開始列へ
    wsL6T.Range(Cells(1, 45), Cells(iEndRowL6, 45)).Copy _
        Destination:=Range(Cells(1, 2), Cells(iEndRowL6, 2))
    '開始列をシャドウ終了列へ
    wsL6T.Range(Cells(1, 3), Cells(iEndRowL6, 3)).Copy _
        Destination:=Range(Cells(1, 46), Cells(iEndRowL6, 46))
    ' 背景色
    wsL6T.Range(Cells(1, 2), Cells(iEndRowL6, 2)).Interior.ColorIndex = 16
    wsL6T.Range(Cells(1, 46), Cells(iEndRowL6, 46)).Interior.ColorIndex = 16
    '// 出現回数
    Call GetSyutugenCnt_CountA(L6T_SHEET, 2, 3, iEndRowL6, 45)
    '// 合計と偶数比率
    Call GetSumAndKigu(L6T_SHEET, 2, 3, iEndRowL6, 45)
    
    '-- L7 -> L7T --------------------------------------
    wsL7.Activate
    Dim iStaRowL7 As Long: iStaRowL7 = 2
    For j = 1 To 37
        wsL7T.Cells(1, j + 2) = j
        wsL7T.Cells(1, j + 2).Interior.ColorIndex = 6
    Next j
    For i = iStaRowL7 To iEndRowL7
        For j = 1 To 7
            If j = 1 Then
                wsL7T.Cells(i, 1) = wsL7.Cells(i, 2)
            End If
            iPos = Trim(wsL7.Cells(i, j + 2))
            wsL7T.Cells(i, iPos + 2) = "〇"
            If Is_Lucky_Num(L7_SHEET, iPos) = True Then
               wsL7T.Cells(i, iPos + 2) = "★"
            End If
        Next j
    Next i
    Call Format_T(L7T_SHEET, iEndRowL7, 38)
    '最終列をシャドウ開始列へ
    wsL7T.Range(Cells(1, 39), Cells(iEndRowL7, 39)).Copy _
        Destination:=Range(Cells(1, 2), Cells(iEndRowL7, 2))
    '開始列をシャドウ終了列へ
    wsL7T.Range(Cells(1, 3), Cells(iEndRowL7, 3)).Copy _
        Destination:=Range(Cells(1, 40), Cells(iEndRowL7, 40))
    ' 背景色
    wsL7T.Range(Cells(1, 2), Cells(iEndRowL7, 2)).Interior.ColorIndex = 16
    wsL7T.Range(Cells(1, 40), Cells(iEndRowL7, 40)).Interior.ColorIndex = 16
    '// 出現回数
    Call GetSyutugenCnt_CountA(L7T_SHEET, 2, 3, iEndRowL7, 39)
    '// 合計と偶数比率
    Call GetSumAndKigu(L7T_SHEET, 2, 3, iEndRowL7, 39)
    '
    ' -------------------------------
    ' 終了処理
    ' -------------------------------
    wsL6.Activate
    Dim sMsg As String
    sMsg = "処理終了" & vbCrLf & _
            " L6 " & vbTab & iEndRowL6 & " 件" & vbCrLf & _
            " L7 " & vbTab & iEndRowL7 & " 件"
            
    MsgBox sMsg, , G_MSG_TIL
    
    Exit Sub
SManError:
    MsgBox "XXXXX ", vbExclamation

End Sub
'
' 合計値と奇数偶数比率
Function GetSumAndKigu(SHEET As String, _
                         iStaRow As Long, iStaCol As Long, _
                         iEndRow As Long, iEndCol As Long) As Boolean
    
    Dim ws                  As Worksheet: Set ws = Worksheets(SHEET)
    Dim i                   As Long
    Dim j                   As Long
    Dim iSum                As Long
    Dim iGuCnt              As Double
    GetSumAndKigu = False
    '//
    ws.Cells(1, iEndCol + 2) = "合計"
    ws.Cells(1, iEndCol + 3) = "偶比%"
    With ws.Range(Cells(1, iEndCol + 2), Cells(1, iEndCol + 3))
        .ColumnWidth = 6
    End With
    '//
    For i = iStaRow To iEndRow
        iSum = 0: iGuCnt = 0
        For j = iStaCol To iEndCol
            '// 合計
            If ws.Cells(i, j) <> "" Then
                iSum = iSum + j - 2
                '// 偶数件数
                If j Mod 2 = 0 Then
                    iGuCnt = iGuCnt + 1
                End If
            End If
            'Debug.Print iKensu
        Next j
        '// 合計セット
        ws.Cells(i, iEndCol + 2) = iSum
        '// 比率セット
        If SHEET = L6T_SHEET Then
           ws.Cells(i, iEndCol + 3) = Format(iGuCnt / 6 * 100, "0")
        End If
        If SHEET = L7T_SHEET Then
           ws.Cells(i, iEndCol + 3) = Format(iGuCnt / 7 * 100, "0")
        End If
    Next i
    '// 戻値
    GetSumAndKigu = True
End Function

'
' 出現件数
Function GetSyutugenCnt_CountA(SHEET As String, _
                         iStaRow As Long, iStaCol As Long, _
                         iEndRow As Long, iEndCol As Long) As Boolean
    
    Dim ws                  As Worksheet: Set ws = Worksheets(SHEET)
    Dim j                   As Long
    GetSyutugenCnt_CountA = False
    On Error Resume Next
    '//
    With ws.Range(Cells(iEndRow + 1, iStaCol), Cells(iEndRow + 1, iEndCol))
     ' 罫線
        .Borders.LineStyle(xlEdgeTop) = xlDashDotDot
        .Borders(xlEdgeTop).Weight = xlMedium
        .Borders.LineStyle(xlEdgeBottom) = xlDashDotDot
        .Borders(xlEdgeBottom).Weight = xlMedium
    End With
    
    For j = iStaCol To iEndCol
         ws.Cells(iEndRow + 1, j) = WorksheetFunction.COUNTA( _
                                    ws.Range(Cells(j, iStaRow), _
                                    ws.Cells(j, iEndRow)))
         'Debug.Print iKensu
    Next j
    '// 戻値
    GetSyutugenCnt_CountA = True
End Function
'
' 行スクロール解放し固定する
Function FreezePanes(SHEET As String, iRow As Integer, iCol As Integer) As Boolean
     Dim ws    As Worksheet: Set ws = Worksheets(SHEET)
     With ActiveWindow
        If .FreezePanes = True Then
           .FreezePanes = False
        End If
        ws.Range(Cells(iRow, iCol), Cells(iRow, iCol)).Select
        .FreezePanes = True
     End With
End Function

' 書式を設定する
Public Function Format_T(SHEET As String, iEndRow As Long, iEndCol As Long) As Boolean

    Dim ws    As Worksheet: Set ws = Worksheets(SHEET)
    Dim bRC   As Boolean
    
    ws.Activate
    
    'クリヤー
    'With Worksheets(M_SHEET)
    '    .Cells.Clear
    'End With
        
    ActiveWindow.Zoom = 100               ' 表示倍率を設定する
    ActiveWindow.DisplayGridlines = False ' 目盛線を非表示
    
    ws.Columns.AutoFit
    
    ' 罫線クリア
    ws.Cells.Borders.LineStyle = xlLineStyleNone
    
    With ws.Range(Cells(1, 3), Cells(iEndRow, iEndCol + 1))
        .Rows.RowHeight = 13.5
        .ColumnWidth = 2.5
     ' セルの文字
        .Rows.AutoFit
        '.EntireColumn.AutoFit
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
     ' 罫線
        .Borders.LineStyle = xlDot
        .Borders(xlEdgeTop).Weight = xlThin
        .Borders(xlEdgeLeft).Weight = xlHairline
        .Borders(xlEdgeRight).Weight = xlHairline
        .Borders(xlEdgeBottom).Weight = xlThin
        
        .Borders(xlEdgeTop).ColorIndex = 15
        .Borders(xlEdgeLeft).ColorIndex = 15
        .Borders(xlEdgeRight).ColorIndex = 15
        .Borders(xlEdgeBottom).ColorIndex = 15
    End With
    
    ' フォント
    With Worksheets(SHEET).Cells.Font
        .Name = "Meiryo UI"
        .Size = 11
        .ColorIndex = 16
    End With
    
    ' 枠の固定(行・列)★
    bRC = FreezePanes(SHEET, 2, 3)
    
    ' カーソル位置を設定する
    ws.Activate
    ws.Cells(3, 3).Select
    
    '.Interior.ColorIndex = G_CLR_YEW
    
    ' // 戻値
    Format_T = True
End Function
'
' My_Lucky_Numの判定
Public Function Is_Lucky_Num(SHEET As String, iNum As Long) As Boolean
    Is_Lucky_Num = True
    ' // My_Lucky_Num
    If SHEET = L6_SHEET Then
        Select Case iNum
            Case 21, 2, 29, 30, 42
                Is_Lucky_Num = True
            Case Else
                Is_Lucky_Num = False
        End Select
    End If
    ' // My_Lucky_Num
    If SHEET = L7_SHEET Then
        Select Case iNum
            Case 21, 2, 29, 30, 35
                Is_Lucky_Num = True
            Case Else
                Is_Lucky_Num = False
        End Select
    End If
End Function
'
' 入力件数を受取り、確認画面を表示する
Public Function IsSeteiCheck(ws As Worksheet, iCnt As Integer) As Boolean

    Dim iRC                As Integer
    Dim sMsg               As String
    
    IsSeteiCheck = False   ' 初期値
    
    sMsg = ""

    '// 入力ファイルの保管フォルダー
    sGFdr = Trim(ws.Cells(L_GYO_FDR, L_RTS_FDR))
    If sGFdr <> "" Then
       '// 指定ありでフォルダー存在チェック
       If IsExistsFdr(ThisWorkbook.Path & "\" & sGFdr) = False Then
            MsgBox sGFdr & " フォルダなし " & vbCrLf & sMsg, vbExclamation, G_MSG_TIL
            Exit Function
       End If
    End If
    
    sMsg = "  場所       " & vbTab & ThisWorkbook.Path & _
           "  BOOK     : " & vbTab & ThisWorkbook.Name & vbCrLf & _
           "  SHEET    : " & vbTab & L_SHEET & vbCrLf & _
           "             " & vbCrLf & _
           "  フォルダ : " & sGFdr & vbCrLf & _
           "  Entry件数: " & vbTab & iCnt

    ' 処理リストに件数ありの場合
    If iCnt <> 0 Then
       '// 確認メッセージを表示
        sMsg = "処理開始 " & vbCrLf & sMsg
        If MsgBox(sMsg, vbYesNo + vbInformation, G_MSG_TIL) = vbYes Then
           IsSeteiCheck = True
        Else
           MsgBox "処理中止 " & vbCrLf & sMsg, vbExclamation, G_MSG_TIL
        End If
    Else
        MsgBox "** NOT Entry ** " & vbCrLf & sMsg, vbExclamation, G_MSG_TIL
    End If
    
End Function
'
' シートの存在確認
Public Function IsExistsSheet(ByVal ShName As String) As Boolean

    Dim ws          As Variant
    
    For Each ws In Sheets
        If LCase(ws.Name) = LCase(ShName) Then
            IsExistsSheet = True ' 存在する
            Exit Function
        End If
    Next

    ' // 戻値
    IsExistsSheet = False
End Function

2024年5月13日月曜日

WWW

Option Explicit
' *******************************************************************************
' *
' * 画像をEXCELに貼り付ける
' *  2024.05.25 Btn1,Btn2 の初期のボタン活性・非活性を非活性にする
' *
' *******************************************************************************
Declare PtrSafe Function OpenClipboard Lib "user32" (Optional ByVal hWnd As Long = 0) As Long
Declare PtrSafe Function CloseClipboard Lib "user32" () As Long
Declare PtrSafe Function EmptyClipboard Lib "user32" () As Long
Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal ms As Long)
Private Declare PtrSafe Function FlashWindowEx Lib "user32.dll" (pfwi As FLASHWINFO) As Long
'
' 64bit環境
Private Type FLASHWINFO
    cbSize      As LongPtr  '構造体サイズ
    hWnd        As LongPtr  'フラッシュするウインドウのハンドル
    dwFlags     As Long     'フラッシュ状態フラグ
    uCount      As Long     'フラッシュ回数
    dwTimeout   As LongPtr  'フラッシュ速度(ミリ秒単位)
End Type
' フラッシュ状態フラグの種類
Const FLASHW_ALL          As Long = &H3 'ウインドウキャプションとタスクバーをフラッシュ
Const FLASHW_CAPTION      As Long = &H1 'ウインドウキャプションをフラッシュ
Const FLASHW_TRAY         As Long = &H2 'タスクバーをフラッシュ
Const FLASHW_STOP         As Long = 0   'フラッシュを停止
Const FLASHW_TIMER        As Long = &H4 'FLASHW_STOPフラグが設定されるまでフラッシュ
Const FLASHW_TIMERNOFG    As Long = &HC 'ウインドウが最前面になるまでフラッシュ
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
 Public Const I_SHEET     As String = "設定"
 Public Const G_APLNAME   As String = "OnTCap 1.6 "
 '2024.05.27
 Public Const G_COLR_GR   As Long = 10      '緑
 Public Const G_COLR_YL   As Long = 6       '黄色緑
 Public Const G_COLR_GY   As Long = 16      'グレー
 '
 Public G_Sh_Canvus       As String
 Public G_Sec             As Integer
 Public G_GapRow          As Integer
 Public G_Id              As String
 Public G_FontName        As String
 Public G_Fontsize        As Double
 Public G_CellRowHeight   As Double
 Public G_CellColWidth    As Double
 Public G_Test_Mode       As String
 Public G_Test_MaxCnt     As Long
 Public G_HlType          As Long
 Public G_HlColor         As Long
 Public G_Status          As String
 Public G_PrintSize       As String
 Public G_PrintOrient     As String
 Public G_Title           As String
 Public G_LogFile         As String
 Public G_BookName        As String
'
 Const PRS_MSG_ROW        As Long = 1      '開始行
 Const PRS_MSG1_COL       As Long = 5      '開始カラム
 Const PRS_MSG2_COL       As Long = 11     '開始カラム
 Const PRS_MSG3_COL       As Long = 20     '開始カラム
 Public G_PRS_MSG1        As String
 Public G_PRS_MSG2        As String
 Public G_PRS_MSG3        As String
'
' ### 基本情報定義 ###'
 Public isLogging         As Boolean   ' キャプチャ収集状態なら True
 Public G_WatchCnt        As Long      ' 監視回数
 Public G_PasteCnt        As Long      ' 貼付回数
'
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
' ### 画面キャプチャ開始 ###'
Sub StartCapture()
 Application.MacroOptions Macro:="StartCapture", ShortcutKey:="j"
 '
 Dim sMsg           As String: sMsg = ""
 '-----------------------------
 ' 初期処理
 '-----------------------------
 Application.OnKey "{ESC}", "StopCapture"    ' Esc キーで停止できるようにしておく
 isLogging = True                            ' キャプチャ取得状態を設定する
 G_WatchCnt = 0: G_PasteCnt = 0
 G_Status = "準備中"
 Application.Caption = "準備中"
 ' 使用権原チェック
 If EnvSecCheck() = False Then
    Exit Sub
 End If
 ' 設定シートの値取込
 If IsSeteiCheck(I_SHEET) = False Then
    Exit Sub
 End If
 '2024.05.27
 If G_Status = "準備中" Then
    Call SetStatusBackColor(G_Sh_Canvus, G_Status)
 End If
 '
 With ThisWorkbook.Sheets(G_Sh_Canvus)
    .Cells(PRS_MSG_ROW, PRS_MSG1_COL).Value = ""
    .Cells(PRS_MSG_ROW, PRS_MSG2_COL).Value = ""
    .Cells(PRS_MSG_ROW, PRS_MSG3_COL).Value = ""
 End With
 'デバックモードの設定
 G_BookName = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - Len(".xlsm"))
 G_LogFile = ThisWorkbook.Path & "\" & G_BookName & "_DebugPrint_" & _
             Format(Now(), "yyyymmdd_hhmmss") & ".txt"
 '
 Call Debug_Printb_Init(G_LogFile)
 '
 ' 描画シートフォーマット
 Canvas_Format (G_Sh_Canvus)
 ' 画面キャプチャのクリップボードリセット
 ClearClipboardImage
 'カーソルの初期処理
 Rows(2).Select                    '行固定
 ActiveWindow.FreezePanes = True
 Range("A3").Select                'カーソルの位置
 '
 '-----------------------------
 ' 主処理
 '-----------------------------
 ' 画面キャプチャ開始
 Application.Caption = "準備中"
 Call ExeCaptute
 '
End Sub
'
' ### 画面キャプチャ貼り付け処理 ###'
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Sub ExeCaptute()
    'On Error GoTo ErrHandler
    Dim CB          As Variant
    Dim size        As Double: size = 1
    Dim height      As Long
    Dim cellHeight  As Double
    Dim sep         As Integer
    Dim i           As Integer
    Dim objShp
    Dim tmpArray()  As Variant
    '2024.05.27
    If G_Status = "起動中" Then
        Call SetStatusBackColor(G_Sh_Canvus, G_Status)
    End If
    '
    G_WatchCnt = G_WatchCnt + 1
    If G_Test_Mode = "ON" And G_WatchCnt > G_Test_MaxCnt Then
       isLogging = True
       Call StopCapture
       Exit Sub
    End If
    '
    CB = Application.ClipboardFormats
    Sleep G_Sec      'インターバル秒数
    '
    If Left(Application.Caption, 3) = "停止中" Then GoTo Quit
    ' 空判定
    If CB(1) <> -1 Then
        '■
        Debug_Printb "[ExeCaptute]", "."
        ReDim tmpArray(UBound(CB) + 1)
        For i = 1 To UBound(CB)    ' クリップボードの中身の分繰り返す
            Dim adr As String: Dim Col As Integer: Dim Row As Integer
            adr = ActiveCell.Address
            Col = ActiveCell.Column: Row = ActiveCell.Row
            'adr = ThisWorkbook.ActiveCell.Address
            'Col = ThisWorkbook.ActiveCell.Column: Row = ThisWorkbook.ActiveCell.Row
            '■
            G_PRS_MSG2 = "CB(" & i & ")=" & CB(i) & " 行列[" & Col & ":" & Row & "] "
            tmpArray(i - 1) = G_PRS_MSG2
            ' 画像判定
            If CB(i) = xlClipboardFormatBitmap Then
                '★
                On Error Resume Next
                'ActiveSheet.Paste
                ThisWorkbook.Sheets(G_Sh_Canvus).Paste
                Sleep G_Sec      'インターバル秒数
                'CurCell.Offset(CurRow, CurCols-1).Value = "■"
                '
                Application.CutCopyMode = False     ' 切り取り・コピーモードを解除
                G_PasteCnt = G_PasteCnt + 1
                '
                On Error Resume Next                ' 以下の計算幅エラー
                '
                'Set objShp = Sheets(G_Sh_Canvus).Shapes(Selection.Name)
                'Set objShp = ThisWorkbook.Sheets(G_Sh_Canvus).Shapes(Selection.Name)
                Set objShp = ActiveSheet.Shapes(Selection.Name)
                objShp.LockAspectRatio = msoTrue    ' サイズ変更も元の比率保持
                objShp.ScaleHeight size, msoTrue    ' 画像サイスをSIZE倍する
                '
                ' 画像高さとセル高さからActiveCellの移動幅を計算
                height = objShp.height                    ' <===★★
                If height = 0 Then
                    height = 300
                End If
                cellHeight = ActiveCell.height
                sep = height / cellHeight + G_GapRow
                '
                ActiveCell.Offset(sep, 0).Select
                'ThisWorkbook.Sheets(G_Sh_Canvus).ActiveCell.Offset(sep, 0).Select
                Dim iNextRow As Integer
                iNextRow = Row + sep
                '
                G_PRS_MSG3 = "■計算 画像高:" & height & _
                             " セル高:" & cellHeight & " 間隔:" & sep & _
                             " >>次行:" & iNextRow
                ThisWorkbook.Sheets(G_Sh_Canvus).Cells(PRS_MSG_ROW, PRS_MSG3_COL).Value = _
                             G_PRS_MSG3
                ' 画面キャプチャのクリップボードリセット
                ClearClipboardImage
            End If
        Next i
        '
        Dim tmpMsg As String
        Dim k      As Long
        tmpMsg = ""
        For k = 0 To UBound(tmpArray())
            tmpMsg = tmpMsg & tmpArray(k)
        Next k
        ThisWorkbook.Sheets(G_Sh_Canvus).Cells(PRS_MSG_ROW, PRS_MSG2_COL).Value = _
            Time & " 判定 " & tmpMsg
        Debug_Printb "[ExeCaptute]", Time & " 判定 " & tmpMsg & G_PRS_MSG3
    End If
    '
    G_Status = "起動中"
    Application.Caption = G_Status
    If G_Test_Mode = "ON" Then
        G_PRS_MSG1 = " 監視(現在/最大):" & G_WatchCnt & "/" & G_Test_MaxCnt & _
                     " - " & "貼付:" & G_PasteCnt
        ThisWorkbook.Sheets(G_Sh_Canvus).Cells(PRS_MSG_ROW, PRS_MSG1_COL).Value = _
                     Time & " " & G_PRS_MSG1
    Else
        G_PRS_MSG1 = " 監視(現在/最大):" & G_WatchCnt & "/" & "*" & _
                     " - " & "貼付:" & G_PasteCnt
        ThisWorkbook.Sheets(G_Sh_Canvus).Cells(PRS_MSG_ROW, PRS_MSG1_COL).Value = _
                     Time & " " & G_PRS_MSG1
    End If
    '
    Call Set_FlushSheet(G_Sh_Canvus, G_WatchCnt)
    ' 制御をOSに移します。
    DoEvents
    ' 次回実行予定時刻を設定(数秒ごとに実行)
    If isLogging = True Then
        Dim NextSec
        NextSec = G_Sec / 1000 / 86400
        Application.OnTime Now + NextSec, "ExeCaptute", , isLogging
    End If
    Exit Sub
ToEnd:
' エラー処理
ErrHandler:
    isLogging = False
    Dim ErrMsg As String
    ErrMsg = "ActiveSheet.Name=" & ActiveSheet.Name & vbCrLf & _
             "エラー番号:" & Err.Number & vbCrLf & _
             "エラー内容:" & Err.Description
    MsgBox ErrMsg, vbCritical, G_APLNAME
    Exit Sub
Quit:
    MsgBox "AutoCaptureを停止しました。", vbInformation
    Application.Caption = "停止中"
End Sub
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
' ### 画面キャプチャ停止 ###'
Sub StopCapture()
    Dim sBookOutMsg As String
    Debug_Printb "[StopCapture]", "isLogging=" & isLogging
    If isLogging = True Then
        isLogging = False                         ' キャプチャ取得状態を解除する
        Application.OnKey "{ESC}", ""             ' Esc キーへの登録を解除する
        Call Set_FlushWindow1(G_Sh_Canvus, 0, 0)  '点滅を止める
        G_Status = "停止中"
        Application.Caption = G_Status
        '2024.05.27
        If G_Status = "停止中" Then
            Call SetStatusBackColor(G_Sh_Canvus, G_Status)
        End If
        'シートをコピーしてコピー先のシートを編集する
        Call ShCopy(G_Sh_Canvus, G_Sh_Canvus & "_Out")             'シートコピー
        sBookOutMsg = BookOut("結果", G_Sh_Canvus & "_Out", G_Id)  ' Book保存
        Worksheets(G_Sh_Canvus).Activate
        
        ''2024.05.30
        ' ボタンの活性・非活性
        With Worksheets(G_Sh_Canvus)
            .CommandButton1.Enabled = True
            .CommandButton2.Enabled = False
        End With
        MsgBox "### 画面キャプチャ停止 ### " & vbCrLf & _
               sBookOutMsg, vbInformation, G_APLNAME
    Else
        '2024.05.30
        ' ボタンの活性・非活性
        With Worksheets(G_Sh_Canvus)
            .CommandButton1.Enabled = True
            .CommandButton2.Enabled = False
        End With
        MsgBox "### 画面キャプチャ停止 ### " & vbCrLf & _
               "StopCapture " & "isLogging = " & isLogging, vbExclamation, G_APLNAME
    End If
End Sub

' 2024.05.27
' 状況行の背景色セット
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Public Function SetStatusBackColor(shName As String, _
                            sStatus As String) As Boolean
    SetStatusBackColor = False
    '
    Select Case True
    Case sStatus = "準備中"
        With ThisWorkbook.Sheets(shName).Rows("1:1")
            .Interior.ColorIndex = G_COLR_GR
        End With
    Case sStatus = "起動中"
        With ThisWorkbook.Sheets(shName).Rows("1:1")
            .Interior.ColorIndex = G_COLR_YL
        End With
    Case sStatus = "停止中"
        With ThisWorkbook.Sheets(shName).Rows("1:1")
            .Interior.ColorIndex = G_COLR_GY
        End With
    Case Else
        Debug.Print "shName=" & shName & " sStatus=" & sStatus
    End Select
    '
    SetStatusBackColor = True
End Function
'
' シートコピー
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Public Function ShCopy(shNameS As String, shNameT As String) As String
    '先ソースの存在を確認して存在していれば先シートを削除する
    If IsExistsSheet(shNameT) = True Then
        Application.DisplayAlerts = False
        Worksheets(shNameT).Delete
        Application.DisplayAlerts = True
    End If
    '元シートを末尾にコピーし、Activeになった先シート名を変更する
    Worksheets(shNameS).Copy after:=Worksheets(Worksheets.Count)
    ActiveSheet.Name = shNameT
    '先シートの内容処理
    Worksheets(shNameT).OLEObjects.Delete  'ActiveXのボタン削除
    Rows("1:1").Select                     '1行目を編集する
    Selection.ClearContents
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = G_HlColor
        .PatternTintAndShade = 0
    End With
    ' フォントと行高と列幅
    With Worksheets(shNameT).Cells
        .Font.Name = G_FontName
        .Font.size = G_Fontsize
        .RowHeight = G_CellRowHeight
        .ColumnWidth = G_CellColWidth
    End With
    ' タイトルをセット
    Cells(1, 1).Value = G_Title
End Function
'
' 出力
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Public Function BookOut(wbName As String, _
                        shName As String, _
                        sId As String) As String
    BookOut = ""
    Dim wb              As Workbook
    Dim sBookName       As String
    Dim sPathFull       As String
    Dim sMsg            As String: sMsg = ""
    ' 条件付き書式の解除
    Call Del_CondFormat(shName)
    '
    sBookName = sId & "_" & Trim(shName) & "_" & _
                   Format(Date, "yyyymmdd") & "_" & _
                   Format(Time, "hhmmss") & "_" & G_PasteCnt & ".xlsx"
    sPathFull = ThisWorkbook.Path & "\" & sBookName
    Sheets(Array(shName)).Copy
    Set wb = ActiveWorkbook
    Application.DisplayAlerts = False
    wb.SaveAs fileName:=sPathFull
    wb.Close
    Application.DisplayAlerts = True
    '
    If sBookName <> "" Then
       sMsg = "正常" & vbCrLf & "監視-貼付回:" & _
              G_WatchCnt & " - " & G_PasteCnt & vbCrLf & sBookName
    Else
       sMsg = "異常" & vbCrLf & "監視/貼付回:" & _
              G_WatchCnt & " - " & G_PasteCnt & vbCrLf & sBookName
    End If
    Debug_Printb "[BookOut]", sPathFull
    BookOut = sMsg
End Function
'
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
' ### 描画シードのフォーマット ###'
Function Canvas_Format(shName As String)
    Dim bRC As Boolean
    ' クリア処理
    Call Del_AllCells(shName)
    Call Del_shapes(shName)
    ' フォントと行高と列幅
    With Worksheets(shName).Cells
        .Font.Name = G_FontName
        .Font.size = G_Fontsize
        .RowHeight = G_CellRowHeight
        .ColumnWidth = G_CellColWidth
    End With
    '
    Worksheets(shName).Cells(1, 1).RowHeight = 80
    ' 条件付き書式の設定
    bRC = Set_CondFormat(shName, G_HlType, G_HlColor)
    ' ■画面フラッシュ
    Call Set_FlushWindow1(shName, 4, 0)
    ' 印刷設定
    bRC = PrintSetup(shName, G_PrintSize, G_PrintOrient)
    
    '2024.05.27
    '状況表示行のブランククリア
    With ThisWorkbook.Sheets(shName)
        .Cells(PRS_MSG_ROW, PRS_MSG1_COL).Value = ""    '(1)
        .Cells(PRS_MSG_ROW, PRS_MSG2_COL).Value = ""    '(2)
        .Cells(PRS_MSG_ROW, PRS_MSG3_COL).Value = ""    '(3)
    End With
End Function
'
' シートのすべてのデータとオブジェクトを削除する
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Function Del_AllCells(sSheet As String)
    Debug_Printb "[Del_AllCells]", "RowMax=" & Rows.Count & " ColMax=" & Columns.Count
    Dim rng1 As Range
  '  ★★ 2022.05.25
    Set rng1 = ThisWorkbook.Sheets(sSheet).Range(Cells(2, 1), Cells(Rows.Count, Columns.Count))
    rng1.Clear
    
End Function
'
'エクセルシート上で「画像」を削除する
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Function Del_shapes(sSheet As String)
    Dim myShape As Shape
    For Each myShape In ActiveSheet.Shapes
        If myShape.Type = msoPicture Then
            myShape.Delete
        End If
    Next
End Function
'
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Function Debug_Printb_Init(sFileName As String)
'   実行時バインデイング
    Dim fso  As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    On Error Resume Next
    Call fso.DeleteFile(sFileName, True)  '指定したファイルのパスを削除
    Set fso = Nothing
End Function
'
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Function Debug_Printb(varSec As String, varData As Variant)
    Dim lngFileNum As Long
    Dim mystr      As String * 15
    mystr = varSec
    If G_Test_Mode = "ON" Then
        lngFileNum = FreeFile()
        Open G_LogFile For Append As #lngFileNum
        Print #lngFileNum, Time & " " & mystr & " " & varData
        Close #lngFileNum
    End If
    Debug.Print varData
End Function
'
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
' ### クリップボードリセット ###'
Function ClearClipboardImage()
    ' クリップボードを開く
    If OpenClipboard(0) <> 0 Then
        ' クリップボードから画像データを削除
        EmptyClipboard
        ' クリップボードを閉じる
        CloseClipboard
    End If
End Function
'
' 設定値の読込
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Public Function IsSeteiCheck(shName As String) As Boolean
    On Error Resume Next
    Dim sMsg                As String: sMsg = ""
    Dim wsI                 As Worksheet: Set wsI = Worksheets(shName)
    Dim iRC                 As Integer
    Dim sShCanvus           As String
    Dim sId                 As String
    Dim sSec                As String
    Dim sGapRow             As String
    Dim sFontName           As String
    Dim sFontsize           As String
    Dim sCellRowHeight      As String
    Dim sCellColWidth       As String
    Dim sTestMode           As String
    Dim sTestMaxCnt         As String
    Dim sHlType             As String
    Dim sHlColor            As String
    Dim sPrintSize          As String
    Dim sPrintOrient        As String
    Dim sTitle              As String
    
    IsSeteiCheck = False
    ' 設計シート名存在チェック
    If IsExistsSheet(shName) = False Then
        sMsg = "シートなし " & shName
        GoTo IErrorQuit
    End If
    
    '2024.05.30
    ' ボタンの活性・非活性
    With Worksheets(G_Sh_Canvus)
        .CommandButton1.Enabled = False
        .CommandButton2.Enabled = True
    End With
    
    '
    sShCanvus = sGetSettingValue(wsI, 2, 3)        ' 設定 シート名
    sId = sGetSettingValue(wsI, 3, 3)              ' 設定 ファイルID
    sSec = sGetSettingValue(wsI, 4, 3)             ' 設定 監視間隔
    sGapRow = sGetSettingValue(wsI, 5, 3)          ' 設定 貼付行間
    sFontName = sGetSettingValue(wsI, 6, 3)        ' 設定 文字フォント名
    sFontsize = sGetSettingValue(wsI, 6, 4)        ' 設定 文字フォントサイズ
    sCellRowHeight = sGetSettingValue(wsI, 7, 3)   ' 設定 セル行高
    sCellColWidth = sGetSettingValue(wsI, 7, 4)    ' 設定 セル列幅
    sTestMode = sGetSettingValue(wsI, 8, 3)        ' 設定 テストモード
    sTestMaxCnt = sGetSettingValue(wsI, 8, 4)      ' 設定 テストモード 最件
    sHlType = sGetSettingValue(wsI, 9, 3)          ' 設定 強調セルタイプ
    sHlColor = sGetSettingValue(wsI, 9, 4)         ' 設定 強調セル背景色
    sPrintSize = sGetSettingValue(wsI, 10, 3)      ' 設定 印刷用紙
    sPrintOrient = sGetSettingValue(wsI, 10, 4)    ' 設定 印刷方向
    sTitle = sGetSettingValue(wsI, 11, 3)          ' 設定 タイトル
    '
    If sShCanvus = "" Or sId = "" Or _
       sSec = "" Or sGapRow = "" Or _
       sFontName = "" Or sFontsize = "" Or _
       sCellRowHeight = "" Or sCellColWidth = "" Or _
       sTestMode = "" Or sTestMaxCnt = "" Or _
       sHlType = "" Or sHlColor = "" Then
        sMsg = "何れかの値が空白 "
        GoTo IErrorQuit
    End If
    ' 設計シート名存在チェック
    If IsExistsSheet(sShCanvus) = False Then
        sMsg = "画像貼付のシートなし " & sShCanvus
        GoTo IErrorQuit
    End If
    '
    G_Sh_Canvus = sShCanvus
    G_Id = sId
    G_Sec = sSec
    G_GapRow = sGapRow
    G_FontName = sFontName
    G_Fontsize = sFontsize
    G_CellRowHeight = sCellRowHeight
    G_CellColWidth = sCellColWidth
    G_Test_Mode = sTestMode
    G_HlColor = sHlColor
    G_PrintSize = sPrintSize
    G_PrintOrient = sPrintOrient
    G_Title = sTitle
    '
    ' 監視間隔 数値チェック
    If IsNumeric(sSec) Then
       G_Sec = sSec
       If G_Sec < 1000 Then
          sMsg = "監視間隔 範囲エラー " & sSec
          GoTo IErrorQuit
       End If
    Else
       sMsg = "監視間隔 数値エラー " & sSec
       GoTo IErrorQuit
    End If
    ' 行間 数値チェック
    If IsNumeric(sGapRow) Then
       G_GapRow = sGapRow
       If G_GapRow <= 1 Then
          sMsg = "貼付行間 範囲エラー " & sGapRow
          GoTo IErrorQuit
       End If
    Else
       sMsg = "貼付行間 数値エラー " & sGapRow
       GoTo IErrorQuit
    End If
    ' 文字フォントサイズ 数値チェック
    If IsNumeric(sFontsize) Then
       G_Fontsize = sFontsize
    Else
       sMsg = "文字フォントサイズ 数値エラー " & sFontsize
       GoTo IErrorQuit
    End If
    ' セル行高 数値チェック
    If IsNumeric(sCellRowHeight) Then
       G_CellRowHeight = sCellRowHeight
    Else
       sMsg = "セル行高 数値エラー " & sCellRowHeight
       GoTo IErrorQuit
    End If
    ' セル列幅 数値チェック
    If IsNumeric(sCellColWidth) Then
       G_CellColWidth = sCellColWidth
    Else
    sMsg = "セル列幅 数値エラー " & sCellColWidth
       GoTo IErrorQuit
    End If
    ' TESTモード/ 最大件数
    If Not (sTestMode = "ON" Or sTestMode = "OFF") Then
       sMsg = "TESTモード ON/OFF以外 エラー " & sTestMode
       GoTo IErrorQuit
    End If
    If sTestMode = "ON" And IsNumeric(sTestMaxCnt) Then
       G_Test_MaxCnt = sTestMaxCnt
       If G_Test_MaxCnt <= 0 Then
          sMsg = "TESTモード 最大件数範囲エラー " & G_Test_MaxCnt
          GoTo IErrorQuit
       End If
    End If
    ' 強調セルタイプ 数値
    If IsNumeric(sHlType) Then
       If Not (sHlType = 0 Or sHlType = 1 Or sHlType = 2) Then
          sMsg = "強調セルタイプ 範囲エラー " & sHlType
          GoTo IErrorQuit
       End If
       G_HlType = sHlType
    Else
       sMsg = "強調セルタイプ 数値エラー " & sHlType
       GoTo IErrorQuit
    End If
    ' 強調セル背景色 数値チェック
    If IsNumeric(sHlColor) Then
       G_HlColor = sHlColor
    Else
       sMsg = "強調セル背景色 数値エラー " & sHlColor
       GoTo IErrorQuit
    End If
    '
    sMsg = " シート名  " & vbTab & G_Sh_Canvus & vbCrLf & _
           " 監視間隔  " & vbTab & G_Sec & " ms " & vbCrLf & _
           " 貼付行間  " & vbTab & G_GapRow & " 行 " & vbCrLf & _
           " ファイルID" & vbTab & G_Id & vbCrLf & vbCrLf & _
           " 文字    " & vbTab & "フォント:" & G_FontName & _
                        " サイズ:" & G_Fontsize & vbCrLf & _
           " セル    " & vbTab & "行高:" & G_CellRowHeight & _
                        " 列幅:" & G_CellColWidth & vbCrLf & _
           " テスト   " & vbTab & G_Test_Mode & vbTab & _
                        "[ON時 回数制限:" & G_Test_MaxCnt & "]" & vbCrLf & _
           " 強調セル  " & vbTab & "タイプ:" & G_HlType & _
                        " 背景色:" & G_HlColor & vbCrLf & _
           " 印刷    " & vbTab & "用紙:" & G_PrintSize & _
                        " 方向:" & G_PrintOrient & vbCrLf & _
           " タイトル  " & vbTab & G_Title
    If G_Test_Mode = "ON" Then
       ' ■Yes or Noの場合
       If MsgBox("設定" & vbCrLf & _
                 "■処理を開始しますか?" & vbCrLf & vbCrLf & _
                 sMsg, vbYesNo, G_APLNAME & " [設定]") = vbNo Then
            '2024.05.30
            ' ボタンの活性・非活性
            With Worksheets(G_Sh_Canvus)
                .CommandButton1.Enabled = True
                .CommandButton2.Enabled = False
            End With
          Exit Function
       Else
            '2024.05.30
            ' ボタンの活性・非活性
            With Worksheets(G_Sh_Canvus)
                .CommandButton1.Enabled = False
                .CommandButton2.Enabled = True
            End With
       End If
    End If
    IsSeteiCheck = True
    Exit Function
IErrorQuit:
    '2024.05.30
    ' ボタンの活性・非活性
    With Worksheets(G_Sh_Canvus)
        .CommandButton1.Enabled = True
        .CommandButton2.Enabled = False
    End With
    MsgBox sMsg, vbCritical, G_APLNAME
    Exit Function
End Function
'
' 条件付き書式の設定
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Function Set_CondFormat(sSheet As String, lType As Long, lColor As Long) As Boolean
    Set_CondFormat = True
    '
    Worksheets(sSheet).Activate
    ' 条件付き書式の設定
    Worksheets(sSheet).Cells.FormatConditions.Delete
    '
    Select Case True
    Case lType = 0
    Case lType = 1
        ThisWorkbook.Worksheets(sSheet).Cells.Select
        Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
                "=OR(CELL(""ROW"")=ROW(),CELL(""COL"")=COLUMN())"
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = lColor
            .TintAndShade = 0
        End With
        Selection.FormatConditions(1).StopIfTrue = False
    Case lType = 2
        ThisWorkbook.Worksheets(sSheet).Cells.Select
        Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
                "=AND(CELL(""ROW"")=ROW(),CELL(""COL"")=COLUMN())"
        Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With Selection.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = lColor
            .TintAndShade = 0
        End With
        Selection.FormatConditions(1).StopIfTrue = False
    Case Else
        Set_CondFormat = False
    End Select
End Function
'
' 条件付き書式の設定の解除
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Function Del_CondFormat(sSheet As String)
    'Worksheets(sSheet).Activate
    ThisWorkbook.Worksheets(sSheet).Activate
    ' 条件付き書式の設定
    Worksheets(sSheet).Cells.FormatConditions.Delete
End Function
'
' 気付表示
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Function Set_FlushWindow1(sSheet As String, lFg As Long, lTimeOut As Long)
    Dim tFlashInfo As FLASHWINFO
    Dim hWndFlash  As LongPtr
    Dim lRet       As Long
    ' フラグ複数設定
    If lFg = 4 Then
        tFlashInfo.dwFlags = FLASHW_ALL Or FLASHW_TIMER
    End If
    If lFg = 0 Then
        tFlashInfo.dwFlags = FLASHW_STOP
    End If
    ' フラッシュ設定
    With tFlashInfo
        .cbSize = Len(tFlashInfo)
        .hWnd = Application.hWnd
        '.uCount = luCount
        .dwTimeout = lTimeOut
    End With
    ' 指定の設定でウインドウをフラシュする
    lRet = FlashWindowEx(tFlashInfo)
End Function
'
' 気付表示2
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Function Set_FlushSheet(sSheet As String, iCnt As Long)
    ' フラッシュ設定(シートの色をスイッチする)
    If iCnt \ 2 = 0 Then
        ThisWorkbook.Worksheets(sSheet).Tab.ColorIndex = xlColorIndexNone
        ThisWorkbook.Worksheets(sSheet).Tab.ColorIndex = 2
    Else
        ThisWorkbook.Worksheets(sSheet).Tab.ColorIndex = 6
    End If
    Application.ScreenUpdating = True
End Function
'
' 印刷設定
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Public Function PrintSetup(shName As String, _
                           sSize As String, sHoukou As String) As Boolean
    PrintSetup = False
    ' 用紙サイズと方向
    Select Case True
    Case sSize = "A4" And sHoukou = "横"
        With Sheets(shName).PageSetup
            .PaperSize = xlPaperA4
            .Orientation = xlLandscape
        End With
    Case sSize = "A4" And sHoukou = "縦"
        With Sheets(shName).PageSetup
            .PaperSize = xlPaperA4
            .Orientation = xlPortrait
        End With
    Case sSize = "B4" And sHoukou = "横"
        With Sheets(shName).PageSetup
            .PaperSize = xlPaperB4
            .Orientation = xlLandscape
        End With
    Case sSize = "B4" And sHoukou = "縦"
        With Sheets(shName).PageSetup
            .PaperSize = xlPaperB4
            .Orientation = xlPortrait
        End With
    Case sSize = "A3" And sHoukou = "横"
        With Sheets(shName).PageSetup
            .PaperSize = xlPaperA3
            .Orientation = xlLandscape
        End With
    Case sSize = "A3" And sHoukou = "縦"
        With Sheets(shName).PageSetup
            .PaperSize = xlPaperA3
            .Orientation = xlPortrait
        End With
    Case Else
        Debug.Print "sSize=" & sSize & "sHoukou=" & sHoukou
    End Select
    ' --
    With Sheets(shName).PageSetup
        ' 余白
        .LeftMargin = Application.CentimetersToPoints(1)
        .RightMargin = Application.CentimetersToPoints(1)
        .TopMargin = Application.CentimetersToPoints(1)
        .BottomMargin = Application.CentimetersToPoints(1)
        .HeaderMargin = Application.CentimetersToPoints(0)
        .FooterMargin = Application.CentimetersToPoints(0)
        ' ズーム(すべての列を1ページ)
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = False
        ' ヘッダーとフッター
        .CenterHeader = "&A"
        .RightHeader = "&D"
        .CenterFooter = "&P" & "/" & "&N"
    End With
    PrintSetup = True
End Function
'
' ブックファイルが開いているか確認
Public Function isBookOpen(bookName) As Boolean
    Dim wb              As Workbook
    Dim sBookName       As String
    sBookName = bookName
    If InStrRev(sBookName, "\") > 0 Then
       sBookName = Mid(sBookName, InStrRev(sBookName, "\") + 1)
    End If
    isBookOpen = False
    For Each wb In Worksheets
      If wb.Name = sBookName Then
         isBookOpen = True
         Exit For
      End If
    Next
End Function
'
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Function iGetSettingValue(wsN As Worksheet, _
                          i As Integer, j As Integer) As Long
    Dim iValue As Long
    iValue = 0
    iValue = Trim(wsN.Cells(i, j).Value)
    iGetSettingValue = iValue
End Function
'
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Function sGetSettingValue(wsN As Worksheet, _
                          i As Integer, j As Integer) As String
    Dim sValue As String
    sValue = ""
    sValue = Trim(wsN.Cells(i, j).Value)
    sGetSettingValue = sValue
End Function
'
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
' Sheets に指定した名前のシートの存在確認
Public Function IsExistsSheet(ByVal shName As String)
    Dim ws As Variant
    For Each ws In Sheets
        If LCase(ws.Name) = LCase(shName) Then
            IsExistsSheet = True ' 存在する
            Exit Function
        End If
    Next
    IsExistsSheet = False   ' 存在しない
End Function
' '2024.05.28
' 環境チェック
'---------+---------+---------+---------+---------+---------+---------+---------+---------+
Function EnvSecCheck() As Boolean
    EnvSecCheck = False
    
    Dim iValid      As Integer: iValid = 0
    Dim i           As Integer
    Dim ToDay       As Date
    Dim ExpireDate  As Date
    Dim myUsrArray  As Variant
    '
    ExpireDate = "2024/06/30"
    myUsrArray = Array("Forza1063Z", "forza1063", "Forza1063Z", "Forza1063Z")
    ToDay = Date
    '
    For i = LBound(myUsrArray) To UBound(myUsrArray)
        If Environ("USERNAME") = myUsrArray(i) And ExpireDate > Date Then
            iValid = 1
            Exit For
        End If
    Next i
    '
    If iValid = 0 Then
        MsgBox "利用権限なしか期限超過 ", vbCritical + vbOKOnly, G_APLNAME & " [環境]"
        ThisWorkbook.Close savechanges:=False
        Exit Function
    End If
    EnvSecCheck = True
End Function