Attribute VB_Name = "NewMacros" Sub graphpaper() Attribute graphpaper.VB_Description = "Macro created 11/8/2007 by chabot " Attribute graphpaper.VB_ProcData.VB_Invoke_Func = "Normal.NewMacros.graphpaper" ' ' graphpaper Macro ' Macro created 11/8/2007 by carol conway on chabot computer ' Dim sglBegfinX As Single Dim sglEndX As Single Dim sglBeginY As Single Dim sglEndY As Single Dim Interval As Single Dim LineCount As Single Dim VerticalGridLines As Integer Dim HorizontalGridLines As Integer Dim GridWidth As Single Dim GridHeight As Single Dim UserChoice As String Dim oLine As Shape 'set the line width in points Const LINE_WIDTH As Integer = 2 'set whether to delete the old grid, if any Const DELETE_OLD_GRID As Boolean = True 'delete the old grid If DELETE_OLD_GRID Then On Error Resume Next ActiveDocument.Range.ShapeRange.Delete On Error GoTo 0 End If 'Prompt user to specify the size of squares desired PromptUser: UserChoice = InputBox("Enter size of squares in points:" & vbLf & vbLf & _ "(Value must be between 1 and 72)" & vbLf & _ "9 points = 1/8 inch" & vbLf & _ "12 points = 1/6 inch" & vbLf & _ "18 points = 1/4 inch" & vbLf & _ "24 points = 1/3 inch" & vbLf & _ "36 points = 1/2 inch" & vbLf & _ "72 points = 1 inch", "Create graph paper") 'If the size requested in outside range reprompt user or accept cancel from user and quit If IsNumeric(UserChoice) Then Interval = Val(UserChoice) If Interval > 72 Or Interval < 2 Then MsgBox "Value must be between 1 and 72.", _ vbOKOnly + vbInformation, "Value out of Range" GoTo PromptUser End If ElseIf UserChoice = "" Then GoTo EndGracefully Else GoTo PromptUser End If 'Calculate beginning and ending positions pased on page size and margins With ActiveDocument.Sections.First.PageSetup sglBeginX = .LeftMargin sglEndX = .PageWidth - .RightMargin sglBeginY = .TopMargin sglEndY = .PageHeight - .BottomMargin End With 'Caluculate how many squares can fit in available area HorizontalGridLines = Int((sglEndY - sglBeginY) / Interval) VerticalGridLines = Int((sglEndX - sglBeginX) / Interval) 'calulate size of finished grid based on size of the number of lines and size of the squares GridWidth = VerticalGridLines * Interval GridHeight = HorizontalGridLines * Interval 'draw the horizontal lines For LineCount = 0 To HorizontalGridLines Set oLine = ActiveDocument.Shapes.AddLine( _ BeginX:=sglBeginX, _ BeginY:=sglBeginY + LineCount * Interval, _ EndX:=sglBeginX + GridWidth, _ EndY:=sglBeginY + LineCount * Interval) oLine.Line.Weight = LINE_WEIGHT Next LineCount 'draw the vertical lines For LineCount = 0 To VerticalGridLines Set oLine = ActiveDocument.Shapes.AddLine( _ BeginX:=sglBeginX + LineCount * Interval, _ BeginY:=sglBeginY, _ EndX:=sglBeginX + LineCount * Interval, _ EndY:=sglBeginY + GridHeight) oLine.Line.Weight = LINE_WEIGHT Next LineCount 'release the oLine object from memory Set oLine = Nothing EndGracefully: End Sub