
Στο παράδειγμα που ακολουθεί δημιουργούμε αυτόματα ένα νέο έγγραφο παραγγελίας:
Sub main()
Dim wd As Word.Application
Dim doc As Word.Document
Set wd = New Word.Application
wd.Visible = True
Set doc = Word.Documents.Add
' Insert title date and items
Dim r As Word.Range
Set r = doc.Paragraphs(1).Range
r.InsertAfter ("Replacement Part Order")
r.InsertParagraphAfter
r.InsertAfter ("Date:" & Date)
r.InsertParagraphAfter
r.InsertAfter ("Please dispatch the following parts:")
r.InsertParagraphAfter
r.InsertParagraphAfter
' 7 random parts
For i = 1 To 7
r.InsertAfter Str(i) + ". Part code " + Format(Int(Rnd * 10000 + 1), "000000") + " qty " + Str(Int(Rnd * 100 + 1))
r.InsertParagraphAfter
Next i
r.Paragraphs(1).Alignment = wdAlignParagraphCenter
' Format title
Dim pr As Word.Range
Set r = doc.Paragraphs(1).Range
Set pr = doc.Range(r.Start, r.End)
pr.Font.Bold = True
pr.Font.Size = 14
pr.Font.Name = "Arial"
End Sub
