A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
You will need to code for the Workbook object rather than the individual Worksheet objects. You will alos require multiple routines to cover various scenarios.
Tap Alt+F11 and when the VBE opens, right click ThisWorkbook from the Project Explorer (upper-right) and select View Code. Paste the following into the new pane titled something like Book1 - ThisWorkbook (Code),
Private Sub Workbook_Open()
On Error Resume Next
Application.Caption = ActiveSheet.Range("P9")
ActiveWorkbook.Windows(1).Caption = ActiveSheet.Range("C6")
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
On Error Resume Next
Application.Caption = Sh.Range("P9")
ActiveWorkbook.Windows(1).Caption = Sh.Range("C6")
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
If InStr(1, " $C$6 $P$9 ", Target.Address) > 0 Then
On Error Resume Next
Application.Caption = Sh.Range("P9")
ActiveWorkbook.Windows(1).Caption = Sh.Range("C6")
End If
End Sub
I've added On Error Resume Next to cover a wide variety of scenarios where illegal characters may be assigned to the application window or active worksheet window caption. Tap Alt+Q to return to your worksheet.
You may want to use a self-signed certificate (Sign your own macros for stronger security) and digitally sign your code to avoid macro warnings on Workbook_Open().