-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakuroTool.vb
233 lines (166 loc) · 6.24 KB
/
makuroTool.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
'For excel VB 巨集
'フォルダ内のファイルを処理する
Sub ProcessFiles()
Dim FolderPath As String
Dim FileName As String
Dim wb As Workbook
Dim FileCount As Integer
Dim strPath As String
Dim lastModified As Date
FileCount = 0
FolderPath = Range("C3").Value
FileName = Dir(FolderPath & "*.xlsm")
If ThisWorkbook.Sheets.Count >= 2 Then
DeleteResultSheet
End If
Do While FileName <> ""
FileCount = FileCount + 1
lastModified = FileDateTime(FolderPath & FileName)
Set wb = GetObject(FolderPath & FileName)
CheckAndWriteResult wb, FileCount, FolderPath, lastModified
wb.Close SaveChanges:=False
FileName = Dir
Loop
MsgBox ("終わりました。")
End Sub
'結果シートがある時、古い結果シートを削除します
Sub DeleteResultSheet()
Dim ws As Worksheet
Dim resultSheetExists As Boolean
resultSheetExists = False
For Each ws In ThisWorkbook.Sheets
If ws.Name = "result" Then
resultSheetExists = True
Exit For
End If
Next ws
Application.DisplayAlerts = False
ThisWorkbook.Sheets("result").Delete
Application.DisplayAlerts = True
End Sub
'結果をチェックして書き込み
Sub CheckAndWriteResult(wb As Workbook, ByVal FileCount As Integer, ByVal FolderPath As String, ByVal lastModified As Date)
Dim wsSource As Worksheet
Dim wsResult As Worksheet
Dim hasValues As Boolean
Dim hasGokaku As Boolean
Dim cellResult As Range
Dim strIndex As Integer
Set wsSource = wb.Sheets("単体テスト仕様書兼報告書")
'最初にシートを追加する
Set wsResult = AddResultSheet
SettingResultSheet wsResult, FolderPath
'セルのインデックスをするカウント
strIndex = 3 + (FileCount - 1)
wsResult.Cells(strIndex, "A").Value = wb.Name
ReadWrite strIndex, wsSource, wsResult, lastModified
hasValues = CheckValues(wsSource)
hasGokaku = CheckGokaku(wsSource)
Set cellResult = wsResult.Cells(strIndex, "C")
WriteResult cellResult, hasValues, hasGokaku
NgColor wsResult, strIndex
End Sub
' シートを追加する関数、シートを返す
Function AddResultSheet() As Worksheet
If ThisWorkbook.Sheets.Count = 1 And ThisWorkbook.Sheets(1).Name <> "result" Then
Set AddResultSheet = ThisWorkbook.Sheets.Add
AddResultSheet.Name = "Result"
Else
Set AddResultSheet = ThisWorkbook.Sheets("Result")
End If
End Function
' シートの書式を設定する
Sub SettingResultSheet(ByVal wsResult As Worksheet, ByVal FolderPath As String)
Dim currentTime As Date
currentTime = Now
With wsResult
.Columns("A").ColumnWidth = 40
.Columns("B").ColumnWidth = 15
.Columns("C").ColumnWidth = 12
.Columns("D").ColumnWidth = 11
.Columns("E").ColumnWidth = 11
.Range("A1").Value = "ファイルパス: " & FolderPath
.Range("B1").Value = "実施日: " & Format(currentTime, "yyyy/mm/dd hh:mm")
.Range("B1:D1").Merge
.Range("A2").Value = "ファイル名"
.Range("B2").Value = "ファイル更新日時"
.Range("C2").Value = "チェック結果"
.Range("D2").Value = "システム名"
.Range("E2").Value = "モジュール名"
.Range("F2").Value = "作成日"
.Range("G2").Value = "作成者"
.Range("H2").Value = "確認日"
.Range("I2").Value = "確認者"
.Range("J2").Value = "実施者"
.Range("K2").Value = "開始日"
.Range("L2").Value = "終了日"
.Range("M2").Value = "状況"
.Range("B:M").HorizontalAlignment = xlCenter
.Range("B1").HorizontalAlignment = xlLeft
.Range("A2:M2").Interior.Color = RGB(102, 204, 255)
End With
End Sub
'読み込みと書き込み
Sub ReadWrite(strIndex As Integer, wsSource As Worksheet, wsResult As Worksheet, ByVal lastModified As Date)
Dim systemsName As Range
Dim moduleName As Range
Dim cellGoukaku As Range
Set systemsName = wsResult.Cells(strIndex, "D")
Set moduleName = wsResult.Cells(strIndex, "E")
Set cellGoukaku = wsResult.Cells(strIndex, "M")
systemsName.Value = wsSource.Range("A3").Value
moduleName.Value = wsSource.Range("E3").Value
cellGoukaku.Value = wsSource.Range("J11").Value
wsResult.Cells(strIndex, "B").Value = lastModified
wsSource.Range("A6:G6").Copy Destination:=wsResult.Cells(strIndex, "F")
With wsResult.Range("F" & strIndex & ":L" & strIndex)
.Borders.LineStyle = xlNone
.Interior.Pattern = xlNone
End With
End Sub
'作成日から終了日まてに値があるかチェックする
Function CheckValues(ws As Worksheet) As Boolean
Dim i As Integer
For i = 1 To 7
If ws.Cells(6, i).Value = "" Then
CheckValues = False
Exit Function
End If
Next i
CheckValues = True
End Function
' 状況セルの合格をチェックする
Function CheckGokaku(ws As Worksheet) As Boolean
Dim goukakuValue As String
goukakuValue = ws.Range("J11").Value
If goukakuValue = "合格" Then
CheckGokaku = True
Else
CheckGokaku = False
End If
End Function
'書き込みの結果を判断して
Sub WriteResult(ByVal cellResult As Range, ByVal hasValues As Boolean, ByVal hasGokaku As Boolean)
If hasValues And hasGokaku Then
cellResult.Value = "OK"
Else
cellResult.Value = "NG"
cellResult.Font.Color = RGB(255, 0, 0)
End If
End Sub
'値がないか未達の場合は黄色にする
Sub NgColor(ws As Worksheet, ByVal strIndex As Integer)
Dim rng As Range
Dim cell As Range
Dim goukaku As String
Set rng = ws.Range("F" & strIndex & ":M" & strIndex)
For Each cell In rng
If IsEmpty(cell.Value) Then
cell.Interior.Color = RGB(255, 255, 0)
End If
Next cell
goukaku = ws.Range("M" & strIndex).Value
If goukaku = "未達" Or goukaku = "" Then
ws.Range("M" & strIndex).Interior.Color = RGB(255, 255, 0)
End If
End Sub