PowerPoint Macro: List Fonts at ComboBox - Optimization required (Execution too Slow - More than a minute and half)

DrHacker

New Member
Joined
Jun 4, 2018
Messages
33
Experts, i created a form to load in ComboBox ALL Installed Fonts on system & sort them. Macro was created in PowerPoint; it takes More than a minute and a Half to finish the execution and show the form.

It could be accelerated to reduce it (30 secs for example)?

I guess the way that i programmed it is affecting the performance. Someone can support me with suggestions to improve it?

(Added Word Libraries as part of the code to use it)

VBA Code:
Dim fontList As CommandBarControl
Dim Tempbar As CommandBar
Dim i As Long
Dim TempFonts As Variant
    Dim wd As Object, fontID As Variant

    Set wd = CreateObject("Word.Application")

        For Each fontID In wd.FontNames

For i = 0 To cboFontOther.ListCount - 1

cboFontOther.ListIndex = i

If fontID < cboFontOther.Value Then

cboFontOther.AddItem (fontID), i

GoTo Skiphere

End If

Next i

cboFontOther.AddItem (fontID)

Skiphere:

Next

wd.Quit

Set wd = Nothing

    Me.cboFontOther.Text = "Arial"

    On Error Resume Next

    With FontSelectionForm

         .StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
         .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)

    End With

End Sub

Form attached as picture.

Name References on the Form

lblFontcboOverLabel = Sample Text (Label)

cboFontOther = ComboBox to select fonts

Frame1 = Frame where font name

Thanks!
 

Attachments

  • Form.png
    Form.png
    8.5 KB · Views: 17

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
How about:

VBA Code:
Private Sub UserForm_Activate()
  Dim wd As Object, fontID As Variant, arrList As Object
  
  Set arrList = CreateObject("System.Collections.ArrayList")
  Set wd = CreateObject("Word.Application")
  
  For Each fontID In wd.FontNames
    arrList.Add fontID
  Next
  arrList.Sort
  cboFontOther.List = arrList.toArray
  
  wd.Quit
  Set wd = Nothing
  Me.cboFontOther.Text = "Arial"
  On Error Resume Next
  With FontSelectionForm
    .StartUpPosition = 0
    .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
    .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
  End With
End Sub
 
Upvote 0
Im glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,572
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top