WORD: Polka Dot Pattern with VBA

1,017 views · Published 8 May 2018 · 10:47 · Indexed 23 September 2026

Channel: Vaclav Krejci · 2018 · Howto & Style

Watch on YouTube

Word tutorials: https://www.youtube.com/playlist?list=PLkTfLuE2Kz-5hELeiPa6iVt97qL0W-aIR
E-book http://youtu.be/Z0jB9xJ5-TU
http://www.facebook.com/BestTextEffectsInWord
http://issuu.com/upir/docs/best_text_effects_in_microsoft_word


-------------------------------------------------------------------------------


Sub polka_dot_pattern()
'
'
'
Dim pagewidth As Long
Dim pageheight As Long
Dim columns As Long
Dim rows As Long
Dim radius As Long
Dim xpos As Long
Dim ypos As Long

columns = 10
rows = 8
'
pagewidth = ActiveDocument.PageSetup.pagewidth
pageheight = ActiveDocument.PageSetup.pageheight

For counter_rows = 0 To (rows - 1)
    For counter_columns = 0 To (columns - 1)
        radius = (Rnd() * 20) + 3
    
        xpos = ((counter_columns * (pagewidth / columns)) + ((pagewidth / columns) / 2)) - (radius / 2)
        ypos = (counter_rows * (pageheight / rows) + ((pageheight / rows) / 2)) - (radius / 2)
        If counter_rows Mod 2 = 1 Then
          xpos = xpos + ((pagewidth / columns) / 2)
        End If
        ActiveDocument.Shapes.AddShape(msoShapeOval, xpos, ypos, radius, radius).Select
    Next counter_columns
Next counter_rows

ActiveDocument.Shapes.SelectAll


End Sub

More from this channel