Solved

VBA / MS Word problem

Posted on 2006-10-23
3
386 Views
Last Modified: 2008-02-01
Hi

Hope someone can help me...

I have a collection (named PointsCollection) of X and Y values that I use to draw rectangle shapes on a word document (named Doc).

X and Y are the left and top values for each rectangle, relatives to the page.

For each Point in PointsCollection

   Set Shp = Doc.Shapes.AddShape( msoShapeRectangle, Point.X, Point.Y, 50, 50 )

next

This works fine but I must only print a maximum of 3 rectangles on each page. If there are any more rectangles then I must add a new pages and start adding the remaining rectangles there.

How can I do this?
0
Comment
Question by:rettiseert
3 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 17794951

dim i as integer


For each Point in PointsCollection

   i = i + 1
   Set Shp = Doc.Shapes.AddShape( msoShapeRectangle, Point.X, Point.Y, 50, 50 )
   if (i = 3) then
       Application.Selection.InsertBreak Type:=wdPageBreak
        i= 0
    end if
next


where application is your word.application
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 17794967
You need to use the Anchor parameter. Put page breaks in and then a paragraph to tie the shapes to.

Option Explicit

Sub InsertShapes(Doc as Word.Document)
    Dim shp As Shape
    Dim p As Word.Paragraph
    Dim t As Integer

    Set p = Doc.Paragraphs.Add(Doc.Bookmarks("\StartOfDoc").Range)
    Set shp = Doc.Shapes.AddShape(msoShapeRectangle, 10, 10, 50, 50, p.Range)
    For t = 2 To 10
        Doc.Bookmarks("\EndOfDoc").Range.InsertBreak wdPageBreak
        Doc.Bookmarks("\EndOfDoc").Range.InsertParagraph
        Set p = Doc.Paragraphs.Last
    Set shp = Doc.Shapes.AddShape(msoShapeRectangle, 10 * t, 10, 50, 50, p.Range)
    Next t
End Sub

0
 
LVL 13

Author Comment

by:rettiseert
ID: 17796053
Hello EDDYKT , I have already tested your suggestion, if you run the code you'll find that it doesn't works as spected


Hi GrahamSkan, thanks!, I think I can work using your suggestion!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question