以下のVBAマクロを解析し、80文字程度で機能説明してください。 Sub GenerateVDICommands() Dim lastRow As Long Dim i As…
- User
以下のVBAマクロを解析し、80文字程度で機能説明してください。
Sub GenerateVDICommands() Dim lastRow As Long Dim i As Long Dim vdiName As String Dim restartCommand As String Dim confirmCommand As String Dim countE As Long Dim countF As Long Dim processE As Boolean Dim processF As Boolean
countE = 0 countF = 0 ' C列の最終行を取得 lastRow = ActiveSheet.Cells(ActiveSheet.Rows.count, "C").End(xlUp).row ' データがない場合、エラーメッセージを表示して処理を中断 If lastRow < 4 Then MsgBox "C列(VDI名)にデータを入力してください", vbExclamation, "エラー: データがありません" Exit Sub End If ' E4セル以降が空っぽかを確認 processE = Application.WorksheetFunction.CountA(Range("E4:E" & lastRow)) = 0 ' F4セル以降が空っぽかを確認 processF = Application.WorksheetFunction.CountA(Range("F4:F" & lastRow)) = 0 ' 両方空っぽでない場合、処理をスキップ If Not processE And Not processF Then MsgBox "E列(再起動コマンド)とF列(確認コマンド)の両方にすでにデータが存在しています", vbInformation, "処理不要" Exit Sub End If ' 4行目から最終行までループ(必要な処理のみ実行) For i = 4 To lastRow vdiName = Trim(ActiveSheet.Cells(i, "C").Value) If vdiName <> "" Then ' E列の処理 If processE Then restartCommand = "Restart-VMGuest -VM '" & vdiName & "' -Confirm:$false" ActiveSheet.Cells(i, "E").Value = restartCommand countE = countE + 1 End If ' F列の処理 If processF Then confirmCommand = "$vmlist += '" & vdiName & "'" ActiveSheet.Cells(i, "F").Value = confirmCommand countF = countF + 1 End If End If Next i ' 処理完了後のメッセージボックスを表示 Dim message As String message = "処理が完了しました。" & vbNewLine If processE Then message = message & "E列(再起動コマンド): " & countE & " 件生成" & vbNewLine If processF Then message = message & "F列(確認コマンド): " & countF & " 件生成" MsgBox message, vbInformation, "処理完了"
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.