Skip to content

Instantly share code, notes, and snippets.

@udawtr
Created December 11, 2013 09:37
Show Gist options
  • Save udawtr/7907578 to your computer and use it in GitHub Desktop.
Save udawtr/7907578 to your computer and use it in GitHub Desktop.
Excelファイルを公開する際に保護とロックを忘れないように確認します。
Public Sub Test()
Debug.Print "***********************"
Debug.Print "Excel品質チェックツール"
Debug.Print "***********************"
Dim wb As Workbook
For Each wb In Workbooks
If Not wb Is ActiveWorkbook Then
QC wb
End If
Next
End Sub
Public Sub QC(wb As Workbook)
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
Dim clock As Integer
Dim cunlock As Integer
For Each ws In wb.Worksheets
If ws.Visible Then
Debug.Print "*" & wb.Name & "!" & ws.Name
'保護
If ws.ProtectContents Then
Debug.Print " INFO: ワークシートは保護されています"
Else
Debug.Print " ERR: ワークシートが保護されていません"
End If
'印刷範囲
If ws.PageSetup.PrintArea = "" Then
Debug.Print " ERR: 印刷範囲が設定されていません。"
Else
Debug.Print " INFO: 印刷範囲=" & ws.PageSetup.PrintArea
Set rng = ws.Range(ws.PageSetup.PrintArea)
'計算式とデータの入力規則,ロック
clock = 0
cunlock = 0
For y = 1 To rng.Rows.Count
For x = 1 To rng.Columns.Count
Set cell = rng.Cells(y, x)
If cell.Locked Then clock = clock + 1 Else cunlock = cunlock + 1
'Debug.Print " INFO: " & cell.Address & ": Value=" & cell.Value & ", Formula=" & cell.Formula & ", Lock=" & cell.Locked
'式がロックされていないことの検出
If cell.Locked = False And cell.Value = "" And cell.Formula <> "" Then
Debug.Print " ERR: 式が設定されていますがロックされていません。(" & cell.Address & ")"
End If
Next
Next
'ロック判定
If clock > 0 Then
Debug.Print " INFO: 印刷範囲内にはロック領域があります(ロック=" & CStr(clock) & ",非ロック" & CStr(cunlock) & ")"
Else
Debug.Print " ERR: 印刷範囲内にはロック領域がありません"
End If
End If
End If
Next
Dim r As Range
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment