Good morning.
The short Excel VBA code below, written on a Windows PC, won’t run on Excel for Mac. A very small program that takes a word or phrase from a cell on a worksheet and then returns examples that phrase in all available fonts to rows in the worksheet.
I’m getting: Run-time error ’91’: Object variable or With block variable not set.
Debug takes me to this line: For I = 1 to cbc.ListCount.
A prior line defines cbc: Set cbc = Application.CommandBars.FindControl(ID:=1728)
I suspect that the “(ID:=1728)”, which I think identifies the font selector on the command bar in Windows Excel may need to be different on Mac Excel. But I haven’t been able to find anything on point in my searches.
I'm using a MacBook Pro 14" w/ M1 chip, 32Gb RAM.
The entire code is pretty short, so here it is:
' 18 September 2021
' Macro to display a phrase in all available fonts.
Sub ShowTheFonts()
Application.ScreenUpdating = False
Dim cbc As CommandBarControl, i%
Dim InputPhrase As String
Set cbc = Application.CommandBars.FindControl(ID:=1728)
InputPhrase = Range("InputPhrase").Value
For i = 1 To cbc.ListCount
With Cells(i + 6, 1)
.Value = cbc.List(i)
End With
With Cells(i + 6, 2)
.Formula = "=InputPhrase"
.Font.Name = cbc.List(i)
End With
Next i
Range("B6").Value = i & " fonts"
Columns("B:B").AutoFit
Range("A7").CurrentRegion.Rows.AutoFit
Set cbc = Nothing
Application.ScreenUpdating = True
End Sub
Any help appreciated.