For several of my workbooks I run Overview sheets with charts in them. When printing the Overview sheet, I put my workbook name as header, where the workbook name includes the criteria for the generating the source data (e.g., date range and time stamp plus non-numeric strings).
To draw attention to these numbers/dates/times, I can manually highlight on the print out, but when others print (using a button on the Overview sheet) they don't seem to remember to do that.
I am looking to add some "flare" to my header by underlining the numeric values.
The workbook name character length varies, so I assess character by character. In some cases the code executes after a delay (time varies, but will say that I had a 60 character length name take ~30 seconds), and other times Excel simply doesn't complete execution after several minutes (i will press escape and get the "code execution has been interupted" msgbox; this recently happened for a 48 character name).
As this is working code (sometimes), would you please help critique and possibly help resolve the time delay?
If my approach is inferior, I am open to suggestions, though I understand that, from my time on StackOverflow, subjective questions tend to be closed.
Code in question:
Option Explicit Sub underline_numbers_in_header() Dim i As Long, n As String, z As String n = ActiveWorkbook.Name 'Debug.Print Len(n) For i = 1 To Len(n) If IsNumeric(Mid(n, i, 1)) Then z = z & "&U" & Mid(n, i, 1) & "&U" Else z = z & Mid(n, i, 1) End If ActiveSheet.PageSetup.CenterHeader = "" & z & "" Next i End Sub