Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBA / MS Word problem

Posted on 2006-10-23
3
Medium Priority
?
393 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 1500 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

877 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