Share via

random font macro

Anonymous
2014-01-20T14:33:41+00:00

hi i found this macro on a web 

it is supposed to change fonts randomly and it doesn't work 

any idea on how I can get it work ? 

thanks.

Sub JumbleLetters2()

   Dim oDoc As Object

   Dim oText As Object

   Dim oCursor As Object

   Dim MoreText As Boolean

   Dim nList As Long, nSize As Long

   Dim FontList, FontSize

   oDoc = ThisComponent

   oText = oDoc.Text

   FontList = Array("Arial","Times New Roman","DejaVu Sans","Century Gothic")

   FontSize = Array(12,13,13.5,14,16.2,17)

   nList = UBound(FontList)

   nSize = UBound(FontSize)

   MoreText = True

   oCursor = oText.createTextCursor()

   oCursor.gotoStart(False)

   MoreText = oCursor.goRight(1,True)

   do while MoreText

      oCursor.CharHeight = FontSize(Int(Rnd()* nSize))

      oCursor.CharFontName = FontList(Int(Rnd()* nList))

      oCursor.collapseToEnd()

      MoreText = oCursor.goRight(1,True)

   loop

End Sub

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2014-01-20T15:06:29+00:00

You might do better with the following. It will take an age to run, but it will randomly format each character in a document.

Sub JumbleLetters()

Dim oDoc As Document

Dim oText As Range

Dim nList As Long, nSize As Long, iChar As Long

Dim FontList As Variant, FontSize As Variant

    Set oDoc = ActiveDocument

    Set oText = oDoc.Range

    FontList = Array("Arial", "Times New Roman", "DejaVu Sans", "Century Gothic")

    FontSize = Array(12, 13, 13.5, 14, 16.2, 17)

    nList = UBound(FontList)

    nSize = UBound(FontSize)

    For iChar = 1 To oText.Characters.Count

        oText.Characters(iChar).Font.Size = FontSize(Int(Rnd() * nSize))

        oText.Characters(iChar).Font.name = FontList(Int(Rnd() * nList))

        DoEvents

    Next iChar

End Sub

Was this answer helpful?

6 people found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2014-01-21T12:58:22+00:00

    thanks 

    it works fine!  :)

    just the way i wanted !

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments