Option Explicit Rem This example shows how you can use a template document, which defines a standardized Rem graphical layout for a calendar, to display dynamically generated current month and Rem year data. Rem Rem This uses a combination of the powerful Visual Basic programming feature set and Rem Illustrator's rich graphics and text manipulation capabilities Rem Private Sub MakeCalendar_Click() Dim appRef As New Illustrator.Application Dim templateRef As Illustrator.Document AppActivate "Adobe Illustrator" Rem Open the template file. It is supposed to be in the same folder as Rem the Calendar.exe file appRef.Open CurDir() & "\CalendarTemplate.ai" Set templateRef = appRef.ActiveDocument Rem Determine the number of days in the current month Dim daysInMonth As Integer daysInMonth = 31 While (Not IsDate(CStr(Month(Date)) & "/" & CStr(daysInMonth) & "/" & CStr(Year(Date)))) daysInMonth = daysInMonth - 1 Wend Rem Determine what day of the week the first falls on using Monday as "week day 1" Dim day1DayOfWeek As Integer day1DayOfWeek = Weekday(DateValue(CStr(Month(Date)) & "/01/" & CStr(Year(Date))), vbMonday) Dim daysHeader As Variant daysHeader = Array("M", "T", "W", "T", "F", "S", "S") Rem Fill out a matrix of 6 rows (weeks) times 7 columns (week days) with the day Rem (a month can span up to 6 weeks) Rem value as a string in the correct offset given the position of day 1 in relation Rem to the first Monday of the month Dim rowCnt, colCnt, dayCnt, nRows, nCols As Integer nRows = 6 nCols = 7 Dim calRows(6) As Variant dayCnt = 1 For rowCnt = 1 To nRows calRows(rowCnt - 1) = Array("", "", "", "", "", "", "") For colCnt = 1 To nCols If (dayCnt > daysInMonth) Then Exit For End If If (Not (rowCnt = 1 And colCnt < day1DayOfWeek)) Then calRows(rowCnt - 1)(colCnt - 1) = CStr(dayCnt) dayCnt = dayCnt + 1 End If Next Next Rem Next, join the day strings with tab delimiters to assemble each Rem week's paragraph text. Make the weekend values red. Dim textArt As Illustrator.TextArtItem Dim crntParagraph As Illustrator.Paragraph Dim wordCnt As Integer Dim weekendColor As New Illustrator.Color Dim redColor As New Illustrator.CMYKColor Dim weekdayColor As New Illustrator.Color Dim blackColor As New Illustrator.CMYKColor redColor.Magenta = 100 redColor.Yellow = 90 weekendColor.CMYK = redColor blackColor.Black = 100 weekdayColor.CMYK = blackColor For Each textArt In templateRef.TextArtItems If (textArt.Contents = "#Name") Then textArt.Contents = Format(Date, "mmmm") Else If (textArt.Contents = "#Days") Then Set crntParagraph = textArt.TextRange().Paragraphs(1) crntParagraph.Contents = Join(daysHeader, vbTab) For rowCnt = 1 To nRows Set crntParagraph = textArt.TextRange().Paragraphs.Add crntParagraph.Contents = Join(calRows(rowCnt - 1), vbTab) crntParagraph.FillColor = weekdayColor wordCnt = crntParagraph.Words.Count Rem The first row, and the last row with values may not have Rem values in the weekend cells. Special handling required. If (rowCnt = 1 And wordCnt = 1) Then crntParagraph.Words(wordCnt).FillColor = weekendColor ElseIf (rowCnt > 1 And wordCnt < 7) Then If (wordCnt = 6) Then crntParagraph.Words(wordCnt).FillColor = weekendColor End If Else crntParagraph.Words(wordCnt - 1).FillColor = weekendColor crntParagraph.Words(wordCnt).FillColor = weekendColor End If Next End If End If Next Set textArt = Nothing Set crntParagraph = Nothing Set weekendColor = Nothing Set redColor = Nothing Set weekdayColor = Nothing Set blackColor = Nothing End Sub